Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

Where to place log4j.xml

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
question from:https://stackoverflow.com/questions/2772466/where-to-place-log4j-xml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...