案头见蠹鱼,犹胜凡俦侣。这篇文章主要讲述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 , Rlog4j.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%nlog4j.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%nlog4j.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=FATALlog4j.logger.com.canoo.webtest=WARNlog4j.logger.org.hibernate.ps.PreparedStatementCache=WARN log4j.logger.org.hibernate=DEBUG log4j.logger.org.logicalcobwebs=WARNlog4j.rootCategory=INFO, stdout , Rlog4j.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%nlog4j.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=FATALlog4j.logger.com.canoo.webtest=WARNlog4j.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。
【java出现以下警告(WARN No appenders; WARN Please initialize the log4j的处理方法)】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.
推荐阅读
- Android BlueDroid(蓝牙协议栈)
- Android LCD
- Android 平台电容式触摸屏的驱动基本原理
- Android Camera
- Android之TableLayout表格布局
- Android 6.0 动态申请 音频+拍照+相册 权限
- Android SDK Manager配置
- android.view.animation - LayoutAnimationController 和 GridLayoutAnimationController
- Android Studio 打包生成 APK