开发者

using log4j, where does the configuration file go in my 'main' application?

开发者 https://www.devze.com 2022-12-26 05:02 出处:网络
I have a java main application, and I want to use log4j. I don\'t want to hard code my settings, so where do I put the log4开发者_如何学运维j config file so my application can find it?Generally you p

I have a java main application, and I want to use log4j.

I don't want to hard code my settings, so where do I put the log4开发者_如何学运维j config file so my application can find it?


Generally you put it in your "root package directory" (i.e. base of your classpath) and it'll automatically be picked up - that is where log4j knows to look.


A) in your classpath put a file named log4j.properties
B) Add this to your JVM command line -Dlog4j.configuration=foobar.txt (The configuration file will be foobar.txt)

The exact rules for this are defined in the Log4j documentation in http://logging.apache.org/log4j/1.2/manual.html


By default Log4j uses the classloader to load a resource named log4.properties. So it can be in any directory that is in your classpath.

If you want to use something different then specify resource name using system property log4j.configuration

0

精彩评论

暂无评论...
验证码 换一张
取 消