Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j:WARN No appenders could be found for logger in web.xml

I already put the log4jConfigLocation in web.xml, but I still get the following warning:

log4j:WARN No appenders could be found for logger ⤦     ⤥ (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. 

What did I miss?

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"      "java.sun.com/dtd/web-app_2_3.dtd"> <web-app>     <context-param>         <param-name>contextConfigLocation</param-name>         <param-value>             /WEB-INF/applicationContext.xml         </param-value>     </context-param>     <context-param>         <param-name>log4jConfigLocation</param-name>         <param-value>/WEB-INF/classes/log4j.properties</param-value>     </context-param>      <listener>         <listener-class>             org.springframework.web.util.Log4jConfigListener         </listener-class>     </listener>     <listener>         <listener-class>             org.springframework.web.context.ContextLoaderListener         </listener-class>     </listener>      <servlet>         <servlet-name>suara2</servlet-name>         <servlet-class>             org.springframework.web.servlet.DispatcherServlet         </servlet-class>     </servlet>     <servlet-mapping>         <servlet-name>suara2</servlet-name>         <url-pattern>/*</url-pattern>     </servlet-mapping> </web-app> 
like image 582
cometta Avatar asked Aug 12 '09 13:08

cometta


People also ask

Where is the log4j properties file?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

What is log4j over slf4j?

log4j-over-slf4j. SLF4J ship with a module called log4j-over-slf4j. It allows log4j users to migrate existing applications to SLF4J without changing a single line of code but simply by replacing the log4j. jar file with log4j-over-slf4j.


2 Answers

If that's the entire log4j.properties file it looks like you're never actually creating a logger. You need a line like:

log4j.rootLogger=debug,A1 
like image 105
CodeGoat Avatar answered Sep 21 '22 17:09

CodeGoat


I had log4j.properties in the correct place in the classpath and still got this warning with anything that used it directly. Code using log4j through commons-logging seemed to be fine for some reason.

If you have:

log4j.rootLogger=WARN 

Change it to:

log4j.rootLogger=WARN, console log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.conversionPattern=%5p [%t] (%F:%L) - %m%n 

According to http://logging.apache.org/log4j/1.2/manual.html:

The root logger is anonymous but can be accessed with the Logger.getRootLogger() method. There is no default appender attached to root.

What this means is that you need to specify some appender, any appender, to the root logger to get logging to happen.

Adding that console appender to the rootLogger gets this complaint to disappear.

like image 43
Alain O'Dea Avatar answered Sep 22 '22 17:09

Alain O'Dea