6

I'm using apache commons library and log4j. I have an xml configuration file and a log4j.properties files. I want to specify my log4j properties path inside my xml configuration file. To load my settings i do:

//Loading my xml file
this.config = new XMLConfiguration(this.xmlFileName);  

At this moment the following warnings are raised:

log4j:WARN No appenders could be found for logger (org.apache.commons.configuration.ConfigurationUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

However i haven't yet called any log4j object. Once i have read the xml file i can successfully work with my log4j instance. Is there any way to remove those warnings?

Matteo Codogno
  • 1,569
  • 6
  • 21
  • 36

4 Answers4

4

Check if the log4j.properties file is in the classpath

This link might be useful: http://www.coderanch.com/t/63230/open-source/log-log-WARN-No-appenders

  • I don't want insert my log4j.properties in the classpath, because it is placed external to the jar and in another directory. I want load it at run-time, using the path specified in my application configuration file. – Matteo Codogno Apr 03 '12 at 12:49
1

Log4J outputs this error when a logger is created, but no appender(s) is(are) defined. In practice this error occurs when a logger is created before log4j is initialized.

You say you haven't called any log4j object. But in the error message you see that org.apache.commons.configuration.ConfigurationUtils creates a logger object (see line 66).

You could turn it off before initialization, see How to turn off log4j warnings?

Logger.getRootLogger().setLevel(Level.OFF);

There should be no need to turn it on again since the initialization sets normally the log level of the root logger.

Community
  • 1
  • 1
ChrLipp
  • 15,526
  • 10
  • 75
  • 107
  • Ok, are there any way to disable LOG inside the 'org.apache.commons.configuration.ConfigurationUtils' or configure my log4j properties insied my xml configuration? – Matteo Codogno Apr 03 '12 at 13:11
0

I resolve my issue with this workaround:

//Disable log level
Logger.getRootLogger().setLevel(Level.OFF);

Now i can read my xml configuration file without WARNINGS.
After set log level:

Logger.getRootLogger().setLevel(Level.INFO);
Matteo Codogno
  • 1,569
  • 6
  • 21
  • 36
0

You should at least set the appender and the logger level for the root logger in the loaded log4j configuration file. Otherwise , you will see this warning message.

Example of setting the appender and logger level for the root logger:

#Set root logger 's level and its appender to an appender called CONSOLE which is defined below.
log4j.rootLogger=DEBUG, CONSOLE

#Set the behavior of the CONSOLE appender 
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
Ken Chan
  • 84,777
  • 26
  • 143
  • 172