最近在搭载springMVC运行环境并配置Log4j时启动时,发现控制台报出如下警告:
1 2
| log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly.
|
为解决这样的警告,现提出如下方案:
首先检查log4j.properties文件中是否在log4j.rootLoger中配置日志输出级别;例如:
1
| log4j.rootLogger=WARN,Console
|
在此段代码中的日志响应级别就为WARN警告级;其次要注意在web.xml文件中log监听器的配置:
1 2 3 4 5 6 7 8 9 10 11 12
| <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60000</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener>
|
该段配置一定要配置在ContextLoaderListener监听器之前;
1 2 3
| <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
|
这样问题就解决了。