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 log4j config file so my application can find it?
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 log4j 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