Log4j error - apache commons

I am using apache commons library and log4j. I have an xml configuration file and log4j.properties files. I want to specify the path of the log4j properties in my xml configuration file. To download my settings, follow these steps:

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

The following warnings are raised at this point:

 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 have not yet called any log4j object. Once I read the xml file, I can successfully work with my log4j instance. Is there any way to remove these warnings?

+6
source share
4 answers

Log4J generates this error when creating a registrar, but there are no application (s). In practice, this error occurs when a log is created before log4j is initialized.

You say that you did not call any log4j object. But in the error message, you see that org.apache.commons.configuration.ConfigurationUtils creates a log object (see line 66 ).

You can disable it before initialization, see How to disable log4j warnings?

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

You do not need to enable it again, since initialization usually sets the log level of the root registrar.

+1
source

Check if the log4j.properties file is in the classpath

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

+4
source

You must at least set the boot and log level for the root logger in the downloaded log4j configuration file. Otherwise, you will see this warning message.

Example of setting the application level and registrar for the root registrar:

 #Set root logger 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 
0
source

I solve my problem with this workaround:

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

Now I can read the xml configuration file without WARNINGS.
After the set log level:

 Logger.getRootLogger().setLevel(Level.INFO); 
0
source

Source: https://habr.com/ru/post/912308/


All Articles