Console: 在log4.properties中配置的日志级别以下记录日志消息。

huangapple go评论69阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年1月6日 23:22:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614655.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定