单个Logger的每个附加程序的日志级别 [英] Log Level per appender for a single Logger

查看:71
本文介绍了单个Logger的每个附加程序的日志级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以基于附加程序为单个Logger配置不同的日志级别?

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

我希望将 mylogger 调试消息发送到 logfile 附加程序,但我也希望将 mylogger INFO消息发送到 stdout 附加程序(但对于所有其他记录器,仅警告).使用阈值将标准输出限制为WARN会限制 mylogger 的输出.

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

log4j.appender.stdout.Threshold=INFO

应该在第一轮比赛中更加小心.

Should have been more careful first time round.

这篇关于单个Logger的每个附加程序的日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆