log4j path for logs file

13,251

There are basically three options:

  1. During the build, create a config for log4j which contains an absolute path for the file parameter. Least flexible.

  2. 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:

  1. 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.

  2. 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:

Share:
13,251
Wojtek
Author by

Wojtek

:)

Updated on June 14, 2022

Comments

  • Wojtek
    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?