On Feb 16, 2009, at 3:54 PM, Pat Farrell wrote:
I know this can be done, but I can't figure out how to configure
log4j.properties to send log messages from libraries/packages to
separate streams. I get all of my output in one log file.
I've read all of "The complete log4j manual" by Ceki Gülcü, and just
don't get it.
I want all msgs from com.baz.* to go one place,
all msgs from com.foo.* to go to another
all from net.sourceforge.stripes to go to a third.
the log4j file looks like:
1. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
2. log4j.appender.stdout.Target=System.out
3. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
4. log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p
%c{1}:%L - %m%n
5.
6. log4j.appender.baz=org.apache.log4j.FileAppender
7. log4j.appender.baz.File=/tmp/baz.log
8.
9. log4j.appender.stripesfile=org.apache.log4j.FileAppender
10. log4j.appender.stripesfile.File=/tmp/stripes.log
11.
12. log4j.appender.foo=org.apache.log4j.FileAppender
13. log4j.appender.foo.File=/tmp/foo.log
14. log4j.rootLogger=INFO, stdout, base
15. log4j.logger.net.sourceforge.stripes=DEBUG, stdout, stripesfile
16. log4j.logger.com.foo=DEBUG, stdout, fnfbookfile
17. log4j.logger.com.baz=DEBUG, stdout, fnfbookfile
When I test it, it all goes to the same place
Test code looks like:
1. Logger aLog =
Logger.getLogger("net.sourceforge.stripes.action.Resolution");
2. aLog.error("this is an error");
5. Logger cLog = Logger.getLogger("com.foo.busobj.Address");
6. cLog.error("this is an error address");
7. Logger dLog =
Logger.getLogger("com.baz.database.DBConnectionPool");
8. dLog.error("this is an error DBConnPool");
Thanks
--
Pat Farrell
http://www.pfarrell.com/
You define appenders named "stdout", "baz" and "foo", then you attach
appenders named "stdout", "base" and "stripesfile" to various
loggers. Since "base" and "stripesfile" are not defined, the only
place for the messages to go is to "stdout".
Since you are not setting additivity to false, all messages sent to
"com.foo.*" will be sent to stdout twice, once for its attachment at
"com.foo" and once for its attachment to the rootLogger.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]