Asked  7 Months ago    Answers:  5   Viewed   295 times

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?

 Answers

50

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
Tuesday, June 1, 2021
 
Webroots
answered 7 Months ago
40

If that's the entire log4j.properties file it looks like you're never actually creating a logger. You need a line like:

log4j.rootLogger=debug,A1
Monday, June 21, 2021
 
xrock
answered 6 Months ago
74

There are many possible options for specifying your log4j configuration. One is for the file to be named exactly "log4j.properties" and be in your classpath. Another is to name it however you want and add a System property to the command line when you start Java, like this:

-Dlog4j.configuration=file:///path/to/your/log4j.properties

All of them are outlined here http://logging.apache.org/log4j/1.2/manual.html#defaultInit

Sunday, August 1, 2021
 
Noctis
answered 5 Months ago
47

Yes, presumably it wants the path to the javadoc command line tool that comes with the JDK (in the bin directory, same as java and javac).

Eclipse should be able to find it automatically; are you perhaps running it on a JRE? That would explain the request.

Saturday, September 4, 2021
 
rorymorris
answered 3 Months ago
14

Yes, this is a classpath issue. Log4j is looking for class com.lior.ibd.utils.logging.EclipseLoggingAppender. (probably appender that wrote someone in your organisation?)

If you remove lines:

 <appender name="eclipseErrorView" class="com.lior.ibd.utils.logging.EclipseLoggingAppender"/>

and

 <logger name="com.lior">
   <level value ="warn" /> 
   <appender-ref ref="eclipseErrorView" />
 </logger> 

log4j should handle it.

Or add EclipseLoggingAppender to classpath by locating a appropriate jar file and add it to the classpath. I.e. run

java -cp appender.jar com.mypackage.MyClass
Thursday, November 4, 2021
 
Maxime VAST
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share