java出现以下警告:WARN No appenders;WARN Please initialize the log4j的处理方法
Posted 扫地猿
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java出现以下警告:WARN No appenders;WARN Please initialize the log4j的处理方法相关的知识,希望对你有一定的参考价值。
编译java或引用别的代码时出现以下警告:
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
出现这个的原因是没有初始化log4j配置导致的
这个是个警告如果不上心可以不管,如果想去掉或者把日志记录下来,就要在程序中处理一下。
1.在src同级目录下新建文件夹config,config内新建文件log4j.properties,文件内容如下,每个配置的详细说明请见:http://www.cnblogs.com/likui360/p/7992982.html 可以根据自己的需求进行调整。
log4j.rootCategory=INFO, stdout , R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=D:\\\\Tomcat 5.5\\\\logs\\\\qc.log log4j.appender.R.layout=org.apache.log4j.PatternLayout 1log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n log4j.logger.com.neusoft=DEBUG log4j.logger.com.opensymphony.oscache=ERROR log4j.logger.net.sf.navigator=ERROR log4j.logger.org.apache.commons=ERROR log4j.logger.org.apache.struts=WARN log4j.logger.org.displaytag=ERROR log4j.logger.org.springframework=DEBUG log4j.logger.com.ibatis.db=WARN log4j.logger.org.apache.velocity=FATAL log4j.logger.com.canoo.webtest=WARN log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN log4j.logger.org.hibernate=DEBUG log4j.logger.org.logicalcobwebs=WARN log4j.rootCategory=INFO, stdout , R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=D:\\\\Tomcat 5.5\\\\logs\\\\qc.log log4j.appender.R.layout=org.apache.log4j.PatternLayout 1log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n log4j.logger.com.neusoft=DEBUG log4j.logger.com.opensymphony.oscache=ERROR log4j.logger.net.sf.navigator=ERROR log4j.logger.org.apache.commons=ERROR log4j.logger.org.apache.struts=WARN log4j.logger.org.displaytag=ERROR log4j.logger.org.springframework=DEBUG log4j.logger.com.ibatis.db=WARN log4j.logger.org.apache.velocity=FATAL log4j.logger.com.canoo.webtest=WARN log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN log4j.logger.org.hibernate=DEBUG log4j.logger.org.logicalcobwebs=WARN
2.在程序中导入:
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.apache.log4j.PropertyConfigurator;
3.程序第一行加入初始化语句:
PropertyConfigurator.configure("config/log4j.properties");
重新编译,输出的内容中不再有警告信息,如果想看到就直接把log4j.rootCategory设置成OFF。
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
以上是关于java出现以下警告:WARN No appenders;WARN Please initialize the log4j的处理方法的主要内容,如果未能解决你的问题,请参考以下文章
关于控制台输出 警告 log4j:WARN No appenders could be found for logger
log4j:WARN No appenders could be found for logger 解决办法
log4j:WARN No appenders could be found for logger ().解决方案
log4j:WARN No appenders could be found for logger
使用hibernate出现log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Versio
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).