Lg4j, no appenders could be found for logger

log4j, no appenders could be found for logger

Jetty启动的时候,有如下警告:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


问题:
日志信息在控制台也打印不出来

分析:
从WARN No appenders could be found for logger
Please initialize the log4j system properly这两句来看, 没有任何appender
也没加载相关属性,比如控制台appender


故初步确定, 应该是log4j.proerties配置文件没有找到

解决:
经了解, log4j.proerties默认在classpath下面,才可以被发现,如果你的路径是classpath/config/log4j.properties, 则对log4j来说,是发现不了的.

处理方式1:
在web.xml中添加Log4jConfigListener,如下:
<context-param>    
   <param-name>log4jConfigLocation</param-name>    
   <param-value>classpath:config/log4j.properties</param-value>    
</context-param>      
<listener>    
    <listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>    
</listener>


处理方式2:
把log4j.properties放到src目录下(即去掉了config目录),这种方式在现在普遍用maven开发的项目,可能不大合适,目前配置文件一般习惯上集中放置在src/main/resources/config目录下,故方式1可能更合适一些!

是否还有更好的处理方式,待观察!



你可能感兴趣的:(log4j)