Maybe it looks silly to ask this but I am confused. I referred to Configuring Log4j property but it doesn't seem to help.
I have written a simple web service HelloWorld. And while running it I am getting the error something like this :
log4j:WARN No appenders could be found for logger (org.apache.axis.transport.http.AxisServlet). log4j:WARN Please initialize the log4j system properly.
I am not sure why its happening.
I am generating the web-service using Eclipse and deployed in Tomcat 6.0. I check on Axis Developer's Guide and according to them
log4j.configuration=log4j.properties Use this system property to specify the name of a Log4J configuration file. If not specified, the default configuration file is log4j.properties. A log4j.properties file is provided in axis.jar.
I didn't find log4j.properties in the axis.jar
.
Any help on this?
If the below statment is present in your class then your log4j.properties should be in java source(src) folder , if it is jar executable it should be packed in jar not a seperate file.
Thanks,
You have to create your own
log4j.properties
in the classpath folder.Well, if you had already created the log4j.properties you would add its path to the classpath so it would be found during execution.
Yes, the thingy will search for this file in the classpath.
Since you said you looked into axis and didnt find one, I am assuming you dont have a log4j.properties, so here's a crude but complete example.
Create it somewhere and add to your classpath. Put it for example, in c:/proj/resources/log4j.properties
In your classpath you simple add .......;c:/proj/resources
Those messages are something tricky, enough so that people created this to make it clearer: https://issues.apache.org/bugzilla/show_bug.cgi?id=25747
What's tricky about them is that the warnings are written if Log4j can't find its
log4j.properties
(orlog4j.xml
) file, but also if the file is fine and dandy but its content is not complete from a configuration point of view.The following paragraph is taken from here: http://svn.apache.org/repos/asf/logging/log4j/tags/v1_2_9/docs/TROUBLESHOOT.html
Logging output is written to a target by using an appender. If no appenders are attached to a category nor to any of its ancestors, you will get the following message when trying to log:
Log4j does not have a default logging target. It is the user's responsibility to ensure that all categories can inherit an appender. This can be easily achieved by attaching an appender to the root category.
You can find info on how to configure the root logger (
log4j.rootLogger
) in the log4j documentation, basically adding something as simple as this at the beginning of the file:This should clear those WARN messages you get on startup (make sure you don't already have an appender named
stdout
; also be carefull of what level you give the root logger,debug
will be very verbose and every library in your app will start writing stuff to the console).As about the
log4j.properties
/log4j.xml
, I suggest you place this file in/WEB-INF/classes
as it is important to have it exposed for different tweaks (activating/deactivating logs, changing log levels etc). You can have it inside a JAR in the classpath also (as you specified in your comment), but it will be enclosed in the archive (hopefully in the right place inside the archive) and won't be as easy to handle as if it were in/WEB-INF/classes
.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());
).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 how to determine your classpath value:
or from Java:
System.getProperty("java.class.path")
.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
log4j.properties
looks like: