我想实现以下目标:
All log-messages with TRACE or higher should be logged to log-trace.log
All log-messages with DEBUG or higher should be logged to log-debug.log
In general messages with DEBUG or higher should be logged to stdout, but:
for Class de.foo only INFO or higher should be logged to stdout,
for Class de.bar also TRACE and higher should be logged to stdout.
我设法将文件拆分为工作:
## Root logger
log4j.rootLogger=trace,STDOUT,FILE_DEBUG,FILE_TRACE
## Appenders
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.Threshold=DEBUG
# File appenders
log4j.appender.FILE_DEBUG=org.apache.log4j.RollingFileAppender
log4j.appender.FILE_DEBUG.File=logs/log-debug.log
log4j.appender.FILE_DEBUG.Threshold=DEBUG
log4j.appender.FILE_TRACE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE_TRACE.File=logs/log-trace.log
log4j.appender.FILE_TRACE.Threshold=TRACE
# [..] Layouts
但是,如果我尝试更改标准输出的调试级别,我也会更改文件中的内容,例如
log4j.logger.de.foo=info
使来自 foo 的 TRACE 消息从跟踪日志文件中消失。我正在寻找的可能是这样的:
log4j.appender.FILE_DEBUG.de.foo.Threshold=DEBUG
但这不起作用。谢谢你的帮助 :)