tags:

views:

48

answers:

3

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?

+2  A: 

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.

Ben J
any tips on a simple config file to log to a file?
Blankman
+1  A: 

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

Romain Hippeau
I read through that (quickly), and nothing stood out, but thanks!
Blankman
A: 

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

objects
I am using netbeans, so not sure how I effect the classpath really? You mean dropping the .jar's in my lib folder adds it to my classpath?
Blankman