英文:
Console: logging messages with lower level than configured in log4.properties
问题
这是我的log4j配置文件:
# 根日志记录器选项
log4j.rootLogger=ERROR, file, stdout
# 将日志消息直接记录到日志文件
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logging.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# 将日志消息直接记录到控制台
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
日志级别被设置为错误(ERROR),但在控制台中,我看到许多具有级别(level)为信息(info)或调试(debug)的日志。为什么这些消息被记录到控制台?我的配置无效吗?
示例控制台日志:链接
在我的测试中,在@Before注解中,我有一行代码:PropertyConfigurator.configure("log4j.properties");,也许这是问题的根源?
英文:
This is my log4j configuration file:
# Root logger option
log4j.rootLogger=ERROR, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logging.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Logging level is set to error, but in console I have many logs with level: info or debug.
Why this messages are logged into console? My configuration is invalid?
Example console log: https://pastebin.com/QEHnAYVg
In @Before annotation in my test i have line: PropertyConfigurator.configure("log4j.properties");, maybe there's source of problems?
答案1
得分: 1
missing slf4j-log4j12 dependency: 缺少 slf4j-log4j12 依赖
英文:
Answer: missing slf4j-log4j12 dependency
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论