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?
First import:
Then add below code to main method:
Create a file at path to and add the below code to that file.
This is just a warning.
Fixing
This occurs when the default configuration files
log4j.properties
andlog4j.xml
can not be found and the application performs no explicit configuration.To fix that, simply create/copy
log4j.properties
orlog4j.xml
into your a location on the classpath (usually the same as the jar files).Optionally set java option:
-Dlog4j.configuration=file:///path/to/log4j.properties
.Debugging
For debugging, you may try to use
-Dlog4j.debug=true
parameter.Configuration of
log4j.properties
Sample configuration of
log4j.properties
:Here is another configuration file that uses multiple appenders:
Apache Solr
If using Solr, copy
<solr>/example/resources/log4j.properties
into a location on the classpath.Sample configuration of
log4j.properties
from Solr goes like:See also:
I ran into this issue when trying to build an executable jar with maven in intellij 12. It turned out that because the java manifest file didn't include a class path the log4j properties file couldn't be found at the root level (where the jar file was executed from.)
FYI I was getting the logger like this:
And I was able to get it to work with a pom file that included this:
If
log4j.properties
is indeed on the classpath, you are using Spring Boot to make a WAR file for deployment to an app server, you are omitting aweb.xml
file in favour of Spring Boot's autoconfigure, and you are not getting any log messages whatsoever, you need to explicitly configure Log4j. Assuming you are using Log4j 1.2.x:Log4J display this warning message when Log4j Java code is searching to create a first log line in your program.
At this moment, Log4j make 2 things
log4j.properties
filelog4j.properties
If
log4J
doesn't findlog4j.properties
file or if appender declared inlog4j.rootlogger
are not defined elsewhere inlog4j.properties
file the warning message is displayed.CAUTION: the content of Properties file must be correct.
The following content is NOT correct
because
file
appender is declared in LOWER-CASE inlog4j.rootlogger
statement and defined in log4j.appender statement using UPPER-CASE !A correct file would be
If MAVEN is used, you must put log4j.properties files in
src/main/resources
AND start a MAVEN build.Log4j.properties file is then copied in
target/classes
folder.Log4J use the
log4j.properties
file that it found intarget/classes
!The reason can be lack of the word
static
in some:If I make logger the instance field, I am getting exactly this very warning:
What is worse, the warning points not to
ProcessorTest
, where the mistake lives, but to an absolutely different class (Sender) as a source of problems. That class has correct set logger and need not any changes! We could look for the problem for ages!