Sunday, May 25, 2008

Avoid absolute path in log4j properties file

In order to avoid an absolute path in a log4j.properties file (and hence to be able to add a standard log4j.properties to a cvs), just do the following:

  1. Use a placeholder in the properties file when you indicate the appender file, for instance

    log4j.appender.file.File=${log4j.logFile}


  2. Pass this placeholder value as a VM parameter to the (web) application. The log4j engine will try to resolve the placeholder and eventually fall back on the System parameters, therefore, in our example:

    ... -Dlog4j.logFile=C:/logs/MyApplication.log ...


Easy and perfectly functional!

No comments: