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?
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:
Second approach is to add this standard
log4j.properties
(taken from the above mentioned guide) file to your classpath:My Eclipse installation could not find
log4j.properties
when running JUnit tests from Eclipse, even though the file was located atsrc/test/resources
.The reason was that Eclipse (or the m2e connector) did not copy content from
src/test/resources
to the expected output foldertarget/test-classes
- the root cause was that in the project's properties under Java Build Path -> Source tab -> Source folders on build path -> src/test/resources, somehow there was anExcluded: **
entry. I removed that excluded entry.Alternatively, I could have manually copied
src/test/resources/log4j.properties
totarget/test-classes/log4j.properties
.Quick solution:
add code to main function:
create a file named log4j.properties at /path/to
You use the
Logger
in your code to log a message. TheAppender
is a Object appended to aLogger
to write the message to a specific target. There areFileAppender
to write to text-files or theConsoleAppender
to write to the Console. You need to show your code of the Logger and Appender setup for more help.please read the tutorial for a better understanding of the interaction of Logger and Appender.
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:
The error message should no longer appear.
I faced the same problem when I use log4j2. My problem is caused by using wrong dependent library:
Instead, I should use:
In my case, I have a log4j2.xml defined in my "resources" directory, and specified to use it by: