You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by None None <ja...@hotmail.com> on 2004/09/21 17:16:14 UTC
Setting levels for loggers.
If I understand this correctly...
Let's say I want my application to log it's activity (INFO) to the console
and all it's exceptions (FATAL) to an e-mail...
I would have to configure 2 loggers with different appenders right?
Something like...
log4j.logger.TMI.TestLogs = INFO, L1A1
log4j.appender.L1A1 = org.apache.log4j.ConsoleAppender
log4j.appender.L1A1.layout = org.apache.log4j.PatternLayout
log4j.appender.L1A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
log4j.logger.TMI.TestLogs.Fatal = FATAL, L2A1
log4j.appender.L2A1 = org.apache.log4j.net.SMTPAppender
log4j.appender.L2A1.SMTPHost = somehost
log4j.appender.L2A1.From = Application
log4j.appender.L2A1.To = none@your.business
log4j.appender.L2A1.layout = org.apache.log4j.PatternLayout
log4j.appender.L2A1.layout.ConversionPattern = %-4r %-5p [%t] %37c %3x -
%m%n
I know this works fine, though I dont like the way the loggers are used in
the application and it kinda goes against the purpose of Log4j? Why would
you want to use different/multiple loggers for one application? Am I missing
the whole point of Log4J?
static Logger log = Logger.getLogger(TestLogs.class.getName());
static Logger logF = Logger.getLogger("TMI.TestLogs.Fatal"); // <-- Don't
like the fact of having to declare 2 loggers
PropertyConfigurator.configure("logs.properties");
NDC.push("1");
log.debug("Entering main.");
log.info("Application started.");
// Do something stupid like divide by zero.
try
{
NDC.push("2");
log.info("Calculating...");
int z;
z = 1 / 0;
}
catch(Exception ex)
{
logF.fatal("Exception: " + ex.toString()); // <------- Don't like
}
NDC.pop();
log.info("Application stopped.");
log.debug("Exiting main.");
NDC.pop();
Thank
_________________________________________________________________
Don't just Search. Find! http://search.sympatico.msn.ca/default.aspx The new
MSN Search! Check it out!
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org