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.

时间: 2024-12-21 15:22:21

java出现以下警告:WARN No appenders;WARN Please initialize the log4j的处理方法的相关文章

关于控制台输出 警告 log4j:WARN No appenders could be found for logger

新建struts2项目时出现警告 log4j:WARN No appenders could be found for logger 于是上网搜查了解决方案 转自:最爱NBA 在src下面新建file名为log4j.properties内容如下: # Configure logging for testing: optionally with log filelog4j.rootLogger=WARN, stdout# log4j.rootLogger=WARN, stdout, logfile

log4j:WARN No appenders could be found for logger

log4j:WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system properly. 如果启动时候报如上警告,有两种办法: 1. 检查log4j.properties or log4j.xml是否被load成功了(加载机制见源码:org.apache.log4j.LogManager.class): 2. 检查log4j.properties中有没有定义相应的logger

maven:log4j:WARN No appenders could be found for logger (loggerInfo).或者maven build error:org.apache.maven.lifecycle.LifecycleExecutionExceptio

maven在build构建时,加载资源文件时需要配置资源文件插件: 1,在pom.xml文件中加入 <build> <finalName>${project.build.target.file.name}</finalName> <directory>${basedir}/target</directory>  <sourceDirectory>${basedir}/src/main/java</sourceDirectory&

eclipse:log4j:WARN No appenders could be found for logger

在src下面新建file名为log4j.properties内容如下: # Configure logging for testing: optionally with log file log4j.rootLogger=WARN, stdout log4j.rootLogger=INFO,stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.lo

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.o

上面的报错是在本地java调试(windows) hadoop集群 出现的 解决方案: 在resources文件夹下面创建一个文件log4j.properties(这个其实hadoop安装目录下的 etc/hadoop/log4j.properties 同名,我尝试拿过来用,发现还是不行报错信息如下) log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFa

log4j log4j:WARN No appenders could be found for logger

web项目用log4j配置文件,结果死活不生效,仔细检查配置文件没有问题,结果一直报 log4j:WARN No appenders could be found for logger 火大,于是把源代码拿下来debug,一步步执行,最后终于找到了元凶,泪流满面 原因:log4j的配置文件是带BOM的UTF-8格式,文件最开头有BOM的3字节EF BB BF, 导致log4j.rootLogger 变成了 xxxlog4j.rootLogger (xxx不可见) log4j初始化的时候用root

spring解决&quot;log4j:WARN No appenders could be found for logger&quot;

1 在src下面新建file名为log4j.properties内容如下: # Configure logging for testing: optionally with log file log4j.rootLogger=WARN, stdout # log4j.rootLogger=WARN, stdout, logfile log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout

使用hibernate出现log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version). log4j:WARN Please initialize the log4j system properly.问题的解决办法

问题描述: log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).log4j:WARN Please initialize the log4j system properly. 问题分析: 大概意思就是它没读到log4j的配置信息,然后让你导入它什么的(差不多是这个意思,可能是你导入了,但没配置好) 解决方法: 从原因上分析,其实它是找不到它需要的那个名为log4j.pr

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment)的解决

报错:log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment). 出错原因:缺少日志文件,主要是后面的原因org.springframework.core.env.StandardEnvironment 解决方案:在resource中添加对应的log4j.properties文件,文件内容为 log4j.rootLogger=DEBUG,A1log4j.