log4j path for logs file
There are basically three options:
During the build, create a config for log4j which contains an absolute path for the file parameter. Least flexible.
Use a System property. While this gives you some flexibility, this causes problems when you run in a container (J2EE server) and you have several applications which all use log4j.
The second option comes in two flavors:
You can specify the path for the log file using
${logFile}
in the XML and use-DlogFile=
on the command line to specify the path.You can keep the XML config in a different place and tell log4j to load it when it starts using
-Dlog4j.configuration=/absolute/path/to/log4j.xml
Related articles:
- http://www.jroller.com/rmcmahon/entry/system_properties_in_log4j_properties
- Log4J change File path dynamically
- Log4j: How to configure simplest possible file logging?
- http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/FileAppender.html
Comments
-
Wojtek almost 2 years
I am using log4j for my logs. My application has a simple XML configuration file and I need to have in my config file the path for the log file. At the moment, it's another XML configuration file for log4j that contains this:
<log4j:configuration> <appender name="file" class="org.apache.log4j.FileAppender"> <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler" /> <param name="file" value="log.out" /> (..........)
(
log.out
is the default log which is in the project's directory.) How can I move this configuration into my application's configuration file?