tags:

views:

323

answers:

2

Hi ,

How can we specify were log4j has to look at when trying to find its xml configuration file ?

It seems that by default, log4j looks into the root of a class folder, I can say that using the debug log4j functionality and running my application from the IDE.

However, I don't have any class folder in my jar anymore. And the log4j.xml file is at the root of the jar.

I have already tried to set the option -Dlog4j.configuration=log4j.xml but it doesn't work.

Here is the global structure of my application at the moment :

  • com
  • lib
  • meta-inf
  • log4j.xml

Thanks !

A: 

It finds the log4j.xml using the CLASSPATH. If log4j doesn't find any config file, it will send an error to the console. If you don't see any such error then it is likely that it is finding a config file which may not be the one you are editing. There is a command-line option to force Log4J to report the path of the config file it is using.

From http://wiki.apache.org/logging-log4j/Log4jConfigurationHelp

If you run with "-Dlog4j.debug" then log4j will print out info to standard output telling how it is trying to configure itself. Looking through that will tell you where it is looking for the config file.

Kelly French
Log4j.xml is at the root of my folder. And this folder is included into my classpath. However, it doesn't seem to be picked up by log4j ... :/
Farid
I am aware of this debugging functionnality, but it doesn't seem to be working. The log are just printed out on the console, and I don't see any debug log. I don't have any error... I'm totally lost.
Farid
If the debug parm doesn't make Log4J report the path and filename of the config file being loaded, I'd wonder about how the application was being started. Is this through a batch file? What IDE are you using?
Kelly French
A: 

I don't have any error

So log4j is finding your configuration, otherwise you would get:

log4j:WARN No appenders could be found for logger ().
log4j:WARN Please initialize the log4j system properly.

Also:

The log are just printed out on the console

So that means that you probably need to define a file appender, like FileAppender or RollingFileAppender. The "Configuration" section on the short intro has a few examples.

Dur4ndal