logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Javier Gonzalez" <jagon...@gmail.com>
Subject Re: Different Log4j log file(s) based on Logging Level?
Date Fri, 11 Aug 2006 18:36:59 GMT
>a separate log file. Similarly, I wanted to have CONFIG, SECURITY,
BUSINESSACTIVITY, >PERFORMANCE custom log levels in the same level
below DEBUG.

I think you would be better served, as James points out, by using
different logging hierachies:

Create different loggers for different stuff, for example:

Logger normalLogger = Logger.getLogger(this.getClass());

Logger configLogger = Logger.getLogger("CONFIG."+this.getClass());
Logger securityLogger = Logger.getLogger("SECURITY."+this.getClass());

and so on - and then, instead of doing:

normalLogger.log(MyCustomLevel.CONFIG,logMessage);
normalLogger.log(MyCustomLevel.SECURITY,logMessage);

do this:

configLogger.log(logMessage);
securityLogger.log(logMessage);

It has the added flexibility that you can now categorize levels within
your CONFIG, SECURITY, etc, loggers. For example:

try{
loadConfiguration();
       configLogger.info("Configuration loaded");
 } catch (Exception e){
       configLogger.fatal("Failed to load configuration",e);
}

both logging messages would be dispatched to whatever appenders you
choose to attach to the CONFIG hierachy, and they are correctly
priorized (not loading the configuration is more urgent than normally
loading it)

And you don't have to implement your separate Level extension. You
just turn off additivity at the CONFIG, SECURITY, etc Logger and that
way it doesn't pollute your root logger with those kinds of messages.

Level should be used to separate priority between logging messages. If
the classification you are trying to make is "intended audience", then
conceptually the way to go is different loggers, not different levels.

-- 
Javier González Nicolini

---------------------------------------------------------------------
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