Monday, February 15, 2010

Solving Error - log4j:WARN No appenders could be found for logger

This log4j error is probably the simplest and most common problem ever encountered in Java EE development history.

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Actually it's not even a real problem, but it can be confusing at first. Understandably so because the error message doesn't give any hint over how to "initialize the log4j system properly".

Fortunately, it's very easy. Just save the following code as log4j.properties. Put it inside your classpath root that is WEB-INF/classes. If you're using Maven that would be src/main/resources.

log4j.rootLogger=info, R
log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%-5p %-30.30c{1} %x - %m%n