After adding log4j to my application I get the following output every time I execute my application:
log4j:WARN No appenders could be found for logger (slideselector.facedata.FaceDataParser). log4j:WARN Please initialize the log4j system properly.
It seems this means a configuration file is missing. Where should this config file be located and what is a good start content?
I'm using plain java for developing a desktop application. So no webserver etc...
What are you developing in? Are you using Apache Tomcat?
I have a properties like this in a Java app of mine.
Try to set debug attribut in log4j:configuration node to true.
It prints out information as the configuration file is read and used to configure the log4j environment. You may be got more details to resolve your problem.
You can set up the log level by using setLevel().
The levels are useful to easily set the kind of informations you want the program to display.
For example:
The set of possible levels are:
According to Logging Services manual
If we are using apache commons logging wrapper on top of log4j, then we need to have both the jars available in classpath. Also,
commons-logging.properties
andlog4j.properties/xml
should be available in classpath.We can also pass implementation class and
log4j.properties
name asJAVA_OPTS
either using-Dorg.apache.commons.logging.Log=<logging implementation class name> -Dlog4j.configuration=<file:location of log4j.properties/xml file>
. Same can be done via settingJAVA_OPTS
in case of app/web server.It will help to externalize properties which can be changed in deployment.
As per Apache Log4j FAQ page:
Basically the warning No appenders could be found for logger means that you're using
log4j
logging system, but you haven't added any Appenders (such as FileAppender, ConsoleAppender, SocketAppender, SyslogAppender, etc.) into your configuration file or the configuration file is missing.There are three ways to configure log4j: with a properties file (
log4j.properties
), with an XML file and through Java code (rootLogger.addAppender(new NullAppender());
).log4j.properties
If you've property file present (e.g. when installing Solr), you need to place this file within your classpath directory.
classpath
Here are some command suggestions in Linux how to determine your classpath value:
or from Java:
System.getProperty("java.class.path")
.Log4j XML
Below is a basic XML configuration file for log4j in XML format:
Tomcat
If you're using Tomcat, you may place your
log4j.properties
into:/usr/share/tomcat?/lib/
or/var/lib/tomcat?/webapps/*/WEB-INF/lib/
folder.Solr
For the reference, Solr default
log4j.properties
file looks like:Why can't log4j find my properties file in a J2EE or WAR application?
See also: