请正确初始化log4j系统警告 [英] Please initialize the log4j system properly warning

查看:423
本文介绍了请正确初始化log4j系统警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是错误消息-

log4j:WARN No appenders could be found for logger (SerialPortUtil).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

这是SerialPortUtil类中的调用-

private static final Logger log = Logger.getLogger(SerialPortUtil.class.getSimpleName());
.
.
.
log.info("Serial port " + port.getName() + " is available");

这是我的log4j.properties文件的内容-

Here is the content of my log4j.properties file -

log4j.rootLogger=DebugAppender

#Debug logging
log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender
log4j.appender.DebugAppender.Threshold=DEBUG
log4j.appender.DebugAppender.File=activityLog.log
log4j.appender.DebugAppender.MaxFileSize=200KB
log4j.appender.DebugAppender.MaxBackupIndex=5
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%d{DATE} %t - %m%n

属性文件在类路径上.

一切对我来说都很好,这是怎么回事? DEBUG阈值是否也应该捕获INFO日志记录?

Everything looks right to me, so what's going on? Shouldn't the DEBUG threshold also capture INFO logging?

推荐答案

好的,所以我通过更改它来使其工作

Alright, so I got it working by changing this

log4j.rootLogger=DebugAppender

对此

log4j.rootLogger=DEBUG, DebugAppender

显然您必须先指定rootLogger的日志记录级别?如果我浪费任何人的时间,我深表歉意.

Apparently you have to specify the logging level to the rootLogger first? I apologize if I wasted anyone's time.

此外,我决定回答自己的问题,因为这不是类路径问题.

Also, I decided to answer my own question because this wasn't a classpath issue.

这篇关于请正确初始化log4j系统警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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