问题描述
是否可以基于Appender为单个记录器配置不同的日志级别?
我意识到这类似于此问题,这是我已经知道的,但是问题的问题是,阈值适用于所有登录该appender的日志记录器,而我只希望适用于单个记录器的阈值
即.到目前为止,我有这样的东西:
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
我想要 mylogger 调试消息要发送到 logfile appender,但我也希望将 mylogger 信息发送发送到< stdout appender(但对于所有其他伐木者,只警告).使用阈值限制stdout来警告 mylogger .
的输出推荐答案
aha,我通过更改
修复了它log4j.appender.stdout.Threshold=WARN
to
log4j.appender.stdout.Threshold=INFO
应该更加小心第一次回合.
问题描述
Is it possible to configure different log levels for a single Logger based on the appender?
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 mylogger DEBUG messages to be send to the logfile appender, but I also want mylogger INFO messages to be sent to the stdout appender (but for all other loggers only WARN ings). Using the Threshold to limit stdout to WARN restricts the output of mylogger.
推荐答案
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.