Abhishek kumar Abhishek kumar - 1 year ago 164
Java Question

log4j could not find root logger information. is this ok

I am loading the configuration file using

java.net.URL url=Thread.currentThread().getContextClassLoader().getResource("MyLog4j.xml");

When running this program with log4j debug on its giving this error.

log4j: Reading configuration from URL file:/F:/TestApp/WEB-INF/classes/MyLog4j.xml
log4j: Could not find root logger information. Is this OK?
log4j: Finished configuring.
log4j:WARN No appenders could be found for logger (MyServlet).
log4j:WARN Please initialize the log4j system properly.

I have put the MyLog4j.xml in WebApp/WEB-INF/classes

This is the contents of my MyLog4j.xml

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="appender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="File" value="F:/MyLogs/MyAppLogs.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
<priority value ="debug"/>
<appender-ref ref="appender"/>

I have searched many question on this topic on SO and not getting it work. Can someone please help me here?

If i change the code to configure using properties files, then its working fine.
Contents of properties file

# This sets the global logging level and specifies the appenders
log4j.rootLogger=INFO, myConsoleAppender

# settings for the console appender
log4j.appender.myConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Answer Source

Having just found the solution to this one, I thought I'd share the answer here since this question is still unanswered.

The issue is that you're using the PropertyConfigurator to configure the MyLog4j.xml file. For XML files, you need to use the DOMConfigurator.