views:

2577

answers:

3

What variables to I have to set/pass as arguments to the JVM to get log4j to run properly? And by properly I mean as in just not complain and print to the console. Can I see a typical example?

Note: I need to avoid creating a lo4j.properties file in the application.

+1  A: 

Do you have a log4j configuration file ? Just reference it using

-Dlog4j.configuration={path to file}
Brian Agnew
Brian - not exactly what I was looking for, but I think it is a decent compromise between moving a file into my application and setting the properties via JVM args.
jconlin
I think that as your application becomes more complex (if it will) then the file becomes more manageable as you configure it more. However I confess I'm guessing as to your use case here.
Brian Agnew
+1  A: 

Generally, as long as your log4j.properties file is on the classpath, Log4j should just automatically pick it up at JVM startup.

Natalia
A: 

I know this is already answered, but because you said, this isn't exactly what you are looking for, I would like to point out the following alternative:

You can also use a configuration class instead of the properties or xml file.

-Dlog4j.configuratorClass=com.foo.BarConfigurator

See http://logging.apache.org/log4j/1.2/manual.html for details.

Tim Büthe