尽管isDebugEnabled为true,但log4j调试消息未在控制台中显示 [英] log4j debug messages not showing in console despite isDebugEnabled being true
问题描述
我在我的项目中使用以下代码通过log4j记录调试消息
I am using the following code within my project to log debug messages with log4j
private static final Logger LOG = Logger.getLogger(MyClass.class)
// ...
if(LOG.isDebugEnabled()) {
LOG.debug("my log message");
}
我可以通过在编写调试消息的行添加断点来确认我的log4j配置正确,即LOG.isDebugEnabled()
确实返回true
.
有趣的是,我的调试消息没有显示在我的IDE(IntelliJ)的控制台中,但是将LOG.debug()
更改为LOG.info()
时,该信息消息将按预期记录.
I can confirm that my log4j configuration is correct by adding a break point at the line where the debug message is written, i.e. LOG.isDebugEnabled()
does return true
.
Interestingly, my debug message does not show up in the console of my IDE (IntelliJ), however when changing LOG.debug()
to LOG.info()
, the info message is logged as expected.
有什么想法我应该寻找什么,以便找出这里出了什么问题吗?
Any ideas what I should be looking for in order to find out what's going wrong here?
编辑:这是我的log4j.properties文件
here's my log4j.properties file
log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.Stdout.layout.conversionPattern=%-5p [%d{dd.MM.yy HH:mm:ss}] %C{1} - %m [thread: %t]\n
log4j.appender.Stdout.threshold=info
log4j.appender.StandaloneFile=org.apache.log4j.RollingFileAppender
log4j.appender.StandaloneFile.File=logs/standalone.log
log4j.appender.StandaloneFile.MaxFileSize=5MB
log4j.appender.StandaloneFile.MaxBackupIndex=20
log4j.appender.StandaloneFile.layout=org.apache.log4j.PatternLayout
log4j.appender.StandaloneFile.layout.ConversionPattern=%-5p [%d{dd.MM.yy HH:mm:ss}] %C{1} - %m [thread: %t]\n
log4j.appender.StandaloneFile.threshold=info
log4j.rootLogger=info, Stdout, StandaloneFile
log4j.logger.com.myPacke.package1=info, Stdout, StandaloneFile
log4j.logger.com.myPacke.package2=DEBUG
推荐答案
log4j.appender.Stdout.threshold=info
应该是:
log4j.appender.Stdout.threshold=debug
您只需将控制台阈值设置为信息,这样就不会获得调试级别的日志.
You just set the console threshold to be info, so you're not getting debug level logs.
请注意,您还应将@RollingFileAppender阈值设置为@Stephen C评论的信息.
Be aware you also set the RollingFileAppender threshold to info as @Stephen C commented.
这篇关于尽管isDebugEnabled为true,但log4j调试消息未在控制台中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!