Hi

you are free to choose a logger's name as you like. The convenience to name the 
loggers by the FQN of the surrounding class is useful for your first goal 
(debugging log). To treat some special log outputs I suggest to introduce a 
separate logger with a clear name, let's say "UserAudit". The additivity flag 
should be set to true, so this log output will also be written to the root 
logger (I assume you define the appenders of the debug logging by root logger).
Annother approach would be to introduce some kind of categories by using MDC 
entries ( "DebugLog", "UserAudit",...) and then use filter classes (only in XML 
configuration available) for your different log outputs. The drawback of this 
latter is to surround each log call with calls to MDC.put() and MDC.remove().

Heri

> -----Original Message-----
> From: Barbalace, Richard [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 21, 2006 10:54 PM
> To: [email protected]
> Subject: How to implement multiple loggers per class?
> 
> 
> Hello, all.
> 
> I am working on a large-scale web application where we want 
> categories of
> logging for the following three distinct purposes:
> 1) Debugging code - using a file appender
> 2) Monitoring production servers - using an email appender
> 3) Auditing user behavior - using a file appender
> 
> Currently, we have implemented loggers on a per-class basis 
> for the first
> purpose according to convention:
>       public class MyUserLoginClass {
>               /**
>                * Static logger for this class
>                */
>               private static Logger st_Log = 
>                       Logger.getLogger(MyUserLoginClass.class);
>       .....
> 
> We have been using this system for months and this is fine 
> for the purpose of
> debugging code in individual classes.  But what if I want to 
> have other loggers
> here for the other two purposes?  Is there a convention for 
> naming such loggers,
> which may be used across multiple Java classes?  Is there a 
> canonical technique
> for configuring such loggers so that they remain completely 
> independent of each
> other?
> 
> As a simple example, say I have a class as above for handling 
> user logins to a
> web application.  I want the code to log various information 
> about the class,
> including informative messages (level INFO), warnings (level 
> WARN), and errors
> (level ERROR), as typical; I would follow the common 
> convention for setting up
> this logger.  I also want a separate log recording when a 
> user logs in or logs
> out (INFO), when a user fails to login due to mistyping a 
> password (WARN), and
> other behavior (mainly for auditing invalid user input 
> attempts); the common
> convention fails to address how to handle this case.  These 
> two loggers would
> use the same levels in some cases but send messages to 
> different appenders for
> recording to different files.  What would be an appropriate 
> configuration?
> 
> My initial thought would be to create separate utility classes for the
> monitoring and auditing loggers, and use those classes when 
> instantiating each
> logger in every class requiring them.  Is this reasonable?  
> Is there a better
> technique?
> 
> Has anyone set up a log4j system like this already?  Are 
> there sample config
> files available?
> 
> Thanks for any help that you can provide.
> 
> Richard J. Barbalace
> Software Developer
> Harris Orthopaedics Biomechanics and Biomaterials Laboratory
> Massachusetts General Hospital
> 55 Fruit Street, Jackson 1121
> Boston, MA  02114
> Tel: 617-726-3607
> Fax: 617-726-3883
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to