Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
url=Thread.currentThread().getContextClassLoader().getResource("MyLog4j.xml");
PropertyConfigurator.configure(url);

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"/>
        </layout> 
   </appender>
  <root>
      <priority value ="debug"/>  
      <appender-ref ref="appender"/>
  </root>
</log4j:configuration>

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

EDIT 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=org.apache.log4j.ConsoleAppender
log4j.appender.myConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.myConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
like image 917
Abhishek kumar Avatar asked Oct 28 '13 19:10

Abhishek kumar


1 Answers

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

DOMConfigurator.configure(url);
like image 193
Will Keeling Avatar answered Sep 23 '22 12:09

Will Keeling