logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DeSantis, MJ Mark @ IS (7179)" <Mark.J.DeSan...@L-3com.com>
Subject RE: Wrapping logger
Date Wed, 08 Feb 2006 19:41:52 GMT
I understand now! Thanks a bunch Javier and Curt. That makes things much
simpler and best part about it is that I get to delete a bunch of unneeded
classes now :)

Thanks again,

Mark

-----Original Message-----
From: Curt Arnold [mailto:carnold@apache.org] 
Sent: Wednesday, February 08, 2006 1:19 PM
To: Log4J Users List
Subject: Re: Wrapping logger



On Feb 8, 2006, at 12:47 PM, Javier Gonzalez wrote:

>>
>> Do you think refactoring to a less "extended" approach is a
>> possibility.
>>
>
> At first glance, I'd propose using two loggers:
>
> }catch(Exception ex){
>         // traditional logger, with stack trace
>         ourLogger.fatal("Problem in such-and-such a window: ", ex);
>         // user friendly logger, with verbose messages and no stack  
> trace
>         ourAdvisoryLogger.fatal("The window can not display because of
> xyz");
> }
>
> And then tweak the appenders configuration and such for  
> "ourAdvisoryLogger"
> to get the results you had with the extended Logger.
>

It does sound like you have messages intended for two audiences, one  
set for a diagnostician and another for the user of the application.   
The easiest way to achieve this is to split the hierarchy of logger  
names and reserve a branch for the user-centric messages.  The  
missing part of the earlier code fragment is:

static Logger ourLogger = Logger.getLogger(Foo.class);
static Logger ourAdvisoryLogger = Logger.getLogger("advisory");

or

static Logger ourAdvisoryLogger = Logger.getLogger 
("advisory.com.example.myapp.Foo");


In your configuration, you would attach an appender to the "advisory"  
logger that would go to your advisory window.  You could set the  
"additivity" property on the "advisory" logger to false if you did  
not want the advisory messages going to the diagnosticians log  
assuming that it is attached to the root logger.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message