Mercurial > hg > Blog
diff content/Java/log4j-logger-additivity.md @ 0:4cd9b65e10e4
initial import of the pelican based blog
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 28 Jun 2013 08:48:58 +0200 |
parents | |
children | 1d9382b0329b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/content/Java/log4j-logger-additivity.md Fri Jun 28 08:48:58 2013 +0200 @@ -0,0 +1,18 @@ +Title: Log4j and logger additivity +Date: 2008-02-18 +Tags: log4j, logging +Lang: en + +Sometimes you want to write more than one logfile using logj4. This is possible by defining multiple appenders and specifying an appender for a certain logger like this: + + log4j.appender.A1=org.apache.log4j.ConsoleAppender + .... + log4j.appender.A2=org.apache.log4j.FileAppender + .... + + log4j.rootLogger=DEBUG, A1 + log4j.logger.foo=DEBUG, A2 + +Unfortunately, all output that goes through the logger foo comes out in both appenders, which may not be what you want. The log4j docs talk about *logger additivity* but don't show concrete examples how to configure it. The trick is to configure the additivity **on the logger** and **not on the appender**. (I always fall into that trap). Simply add the following to the example above to stop messages to logger foo come out on A1: + + log4j.additivity.foo = false