Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please initialize the log4j system properly warning

Tags:

java

log4j

Here is the error message -

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

Here is the invocation in the SerialPortUtil class -

private static final Logger log = Logger.getLogger(SerialPortUtil.class.getSimpleName()); . . . log.info("Serial port " + port.getName() + " is available"); 

Here is the content of my log4j.properties file -

log4j.rootLogger=DebugAppender  #Debug logging log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender log4j.appender.DebugAppender.Threshold=DEBUG log4j.appender.DebugAppender.File=activityLog.log log4j.appender.DebugAppender.MaxFileSize=200KB log4j.appender.DebugAppender.MaxBackupIndex=5 log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout log4j.appender.DebugAppender.layout.ConversionPattern=%d{DATE} %t - %m%n 

And the property file is on the classpath.

Everything looks right to me, so what's going on? Shouldn't the DEBUG threshold also capture INFO logging?

like image 750
mre Avatar asked Jan 20 '12 15:01

mre


1 Answers

Add the code

BasicConfigurator.configure(); 

in your static main class as below..

Note: add " \hadoop-2.7.1\share\hadoop\common\lib\commons-logging-1.1.3.jar & \hadoop-2.7.1\share\hadoop\common\lib\log4j-1.2.17.jar " as the external references

import org.apache.log4j.BasicConfigurator;  public class ViewCountDriver extends Configured implements Tool{      public static void main(String[]args) throws Exception{          BasicConfigurator.configure();           int exitcode = ToolRunner.run(new ViewCountDriver(), args);         System.exit(exitcode);      } } 
like image 101
Janani Avatar answered Sep 21 '22 13:09

Janani