Calfater Calfater - 4 months ago 24
Java Question

Log4j default placeholder value

I use log4j with this appender:

<appender name="fileAppenderRoot" class="org.apache.log4j.FileAppender">
<param name="file" value="${log.location}/logFile.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1}] - %m%n" />
</layout>
</appender>


If I start the server with
-Dlog.location=/path/to/logs
, log4j will log into
/path/to/logs/logFile.log
but if I specify nothing, log4j will fail appending to
/logFile.log
.

Is it possible to specify a default placeholder value?

Answer

No. you need to provide a location to write the log file.

If you need to generate the logs in the folder where you war is deployed ,

<param name="file" value="../logs/logFile.log" />

will create logfile in the folder where you have deployed

Read more here