Java 单个 Logger 的每个 appender 的日志级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2154539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Log Level per appender for a single Logger
提问by Joel
Is it possible to configure different log levels for a single Logger based on the appender?
是否可以根据 appender 为单个 Logger 配置不同的日志级别?
I realize this is similar to this question, and this is as far as I had already got myself, but the problem with this is that the threshold applies to all loggers that log to that appender, whereas I only want the threshold to apply to a single logger.
我意识到这与这个问题类似,这是我自己已经掌握的,但问题在于阈值适用于所有记录到该附加程序的记录器,而我只希望阈值适用于单记录器。
i.e. So far I have something like this:
即到目前为止我有这样的事情:
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=WARN
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.logger.mylogger=DEBUG,logfile
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern=${roll.pattern.daily}
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{${datestamp}} [%t] %-5p %C{2} - %m%n
log4j.appender.logfile.File=mylogfile.log
I want myloggerDEBUG messages to be send to the logfileappender, but I also want myloggerINFO messages to be sent to the stdoutappender (but for all other loggers only WARN ings). Using the Threshold to limit stdout to WARN restricts the output of mylogger.
我希望将myloggerDEBUG 消息发送到日志文件appender,但我也希望将myloggerINFO 消息发送到stdoutappender(但对于所有其他记录器,只有 WARN ings)。使用阈值将 stdout 限制为 WARN 会限制mylogger的输出。
采纳答案by Joel
Aha, I fixed it by changing
啊哈,我通过改变来修复它
log4j.appender.stdout.Threshold=WARN
to
到
log4j.appender.stdout.Threshold=INFO
Should have been more careful first time round.
第一次应该更小心。