Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No appenders could be found for logger(log4j)?

I have put log4j to my buildpath, but I get the following message when I run my application:

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

What do these warnings mean? Whats the appender here?

like image 868
maximus Avatar asked Sep 21 '12 14:09

maximus


People also ask

What are Appenders in log4j?

Appenders. Apache log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as consoles, files, sockets, NT event logs, etc. Each Appender object has different properties associated with it, and these properties indicate the behavior of that object.

Where is the log4j properties file?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

What is log4j over slf4j?

log4j-over-slf4j. SLF4J ship with a module called log4j-over-slf4j. It allows log4j users to migrate existing applications to SLF4J without changing a single line of code but simply by replacing the log4j. jar file with log4j-over-slf4j.


2 Answers

This Short introduction to log4j guide is a little bit old but still valid.

That guide will give you some information about how to use loggers and appenders.


Just to get you going you have two simple approaches you can take.

First one is to just add this line to your main method:

BasicConfigurator.configure(); 

Second approach is to add this standard log4j.properties (taken from the above mentioned guide) file to your classpath:

# Set root logger level to DEBUG and its only appender to A1. log4j.rootLogger=DEBUG, A1  # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.ConsoleAppender  # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 
like image 73
maba Avatar answered Sep 24 '22 04:09

maba


It looks like you need to add the location of your log4j.properties file to the Classpath in Eclipse.

Make sure your project is open in Eclipse, then click on the "Run" menu at the top of Eclipse and click on the following:

  1. Run
  2. Run Configurations
  3. Classpath (tab)
  4. User Entries
  5. Advanced (button on the right)
  6. Add Folders
  7. then navigate to the folder that contains your log4j.properties file
  8. Apply
  9. Run

The error message should no longer appear.

like image 43
JDJ Avatar answered Sep 25 '22 04:09

JDJ