Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place log4j.xml

Tags:

log4j

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
like image 421
Farid Avatar asked May 05 '10 10:05

Farid


People also ask

Where do I put log4j files?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

What is log4j XML file?

xml configuration or using log4j. This is the main configuration file having all runtime configurations used by log4j. This file will contain log4j appenders information, log level information and output file names for file appenders.


2 Answers

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.

like image 86
Kelly S. French Avatar answered Oct 15 '22 05:10

Kelly S. French


Suppose your log4j configuration is outside the source tree. If it can't find your configuration file, help it with:

-Dlog4j.configuration=file:///your/path/log4j.xml 

Note the qualifier file:///. It won't work without.

like image 30
rwst Avatar answered Oct 15 '22 04:10

rwst