What variables do I have to set/pass as arguments to the JVM to get log4j to run properly? And by properly I mean not complain and print to the console. Can I see a typical example?
Note: I need to avoid creating a log4j.properties file in the application.
Late to the party as since 2015, Log4J 1.x has reached EOL.
Log4J 2.x onwards the JVM option should be
-Dlog4j.configurationFile=<filename>
P.S.
<filename>
could be a file relative to the class path without thefile:
as suggested in the other answers.The solution is using of the following JVM argument:
If the file is NOT in the classpath (in
WEB-INF/classes
in case of Tomcat) but somewhere on you disk, usefile:
, likeMore information and examples here: http://logging.apache.org/log4j/1.2/manual.html
Relative Path is also ok:
or
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.
See http://logging.apache.org/log4j/1.2/manual.html for details.
Do you have a log4j configuration file ? Just reference it using
where {path to file} should be prefixed with
file:
This seems to have changed (probably with log4j2) to:
See: https://logging.apache.org/log4j/2.x/manual/configuration.html