Location of the log4j configuration file in a program embedding Jetty

I have a server with an embedded Jetty, for which I am now setting up the logging. Unfortunately, I can’t find a location to put the log4j.properties or log4j.xml where they would be found by default by the log4j runtime, resulting in the following error message:

log4j:WARN No appenders could be found for logger (org.eclipse.jetty.util.log).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Unfortunately, the link doesn’t help (at the time of writing). However, it’s possible to specify the location of the configuration file explicitly.

Either in your Java code, before you call any log4j methods:

System.setProperty("log4j.configuration","file:///path/to/log4j.properties");

or on the command line :

java "-Dlog4j.configuration=file://path/to/log4j.properties" -jar ...

You can also debug where log4j looks with the following option on the command line:

java -Dlog4j.debug -jar ...

Which gives in my case :

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@20cf2c80.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@20cf2c80 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@20cf2c80.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@20cf2c80 class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].

Advertisements
This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s