• 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.

  • 相关阅读:
    导出excel
    JS一些记录
    Concat
    (二)《SQL进阶教程》学习记录--GROUP BY、PARTITION BY
    PostgreSQL 时间转换
    vlc+flv.js 摄像头 H5 直播
    echarts label formatter params backgroundColor rich 标签设置背景图并传参
    异步、多线程、Await/Async、Task
    “2+3”等于我的自白
    SignalR:React + ASP.NET Core Api
  • 原文地址:https://www.cnblogs.com/likui360/p/7992879.html
Copyright © 2020-2023  润新知