You may need to tweak this for your own requirements. Almost all of the log4j examples demonstrate using classnames for logger names, however this is a case where you would want to use a slightly different pattern. Hopefully, you have read http://logging.apache.org/log4j/docs/manual.html and understand the concept of a logger hierarchy.

To address your issue, you would want to use logger names like "security" or "security." + classname, "audit" or "audit." + classname, etc. You'd add the class name if you wanted to be able to control the security messages based on the class.

class MyClass {
private static Logger securityLogger = Logger::getLogger("security." + MyClass.class.getName());
private static Logger auditLogger = Logger::getLogger("audit." + MyClass.class.getName());
//
// standard diagnostic logger
private static Logger logger = Logger::getLogger(MyClass.class);
..
..
void doSomething() {
securityLogger.info("attempt to do something");
}
}



In your configuration file, you would configure the root logger to handle general diagnostic logs (that is, every logger that doesn't start with "security" or "audit") and configure "security" and "audit" as appropriate. You may (or may not) want to set additivity to false so that something logged to "security.com.example.foobar" doesn't end up in the general diagnostic log.


log4j.rootLogger=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

log4j.logger.security=WARN,A2
log4j.additivity.security=false

log4j.logger.audit=DEBUG,A3
log4j.additivity.audit=false

#
#  define appenders A2 and A3 as appropriate






On Apr 12, 2005, at 10:10 AM, Darren Hartford wrote:

Hey all,
Having a real hard time finding any information regarding my problem.

I have an application, and within each class I would like to configure
three separate Loggers, each having their own severitys:

SecurityLogger
ErrorLogger
AuditLogger

But, I would like each of these loggers to have their own configuration.
I guess I only have experience with the PropertyConfigurator, which
obviously works on the Singleton pattern. Any pointers on how to
implement something like this? I'm surprised that I can not find any
good information on this practice.


p.s. The subclass examples with the MyLoggerFactory/MyLogger don't seem
to help, so if you reference those need some more information.

TIA
-D


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



Reply via email to