They can all be static loggers, just like you have done. Just give
them a different naming scheme.
private static Logger logger = Logger.getLogger(MyUserLoginClass.class);
private static Logger monitor = Logger.getLogger("monitor");
private static Logger auditor = Logger.getLogger("auditor");
If you want to use the hierarchical behavior of loggers, you can also
have sub-loggers for the monitor and auditor loggers such as
"monitor.event.login" and "monitor.event.logoff" and so on, if you
really care to get that specific. It all depends on how you want to
structure it. As far as hiding the monitor and auditor loggers in
separate utility classes, that's up to you. It is reasonable, but
there's nothing wrong with having any loggers you need defined in
each class. You might want to have static variables defining the
names of the special purpose loggers to they stay consistent.
Jake
At 03:53 PM 4/21/2006, you wrote:
>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]