Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j, Spring MVC, No appenders could be found for logger

The log4j is working fine, however, at server startup, I am getting these warnings:

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.

It's implying the log4j.properties could not be found. But I am not sure how to fix that because everything seems to be working fine.

like image 746
l a s Avatar asked Mar 13 '12 20:03

l a s


People also ask

Why do I see a warning about no Appenders found for logger and please configure log4j properly?

Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"? This occurs when the default configuration files log4j. properties and log4j. xml can not be found and the application performs no explicit configuration.


1 Answers

Place the spring Log4jConfigListener as the first listener in your web.xml.

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 

You set upp the location of the log4j properties in a context-param but you do not need to do this if it is placed on the classpath.

An example is ..

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/resources/log4j.properties</param-value>
</context-param>
like image 137
Marcus Blackhall Avatar answered Sep 20 '22 06:09

Marcus Blackhall