configure log4j to log to custom file at runtime

You can also do this from the file. Using the sample file below I have added the system property ${}:

# logfile is set to be a RollingFileAppender
log4j.appender.logfile.layout.ConversionPattern=[%-5p]%d{yyyyMMdd@HH\:mm\:ss,SSS}\:%c - %m%n

The log file name can then be set two different ways:

  1. As a command line, system property passed to java “{logfile}”
  2. In the java program directly by setting a system property (BEFORE you make any calls to log4j).

    System.setProperty(“”,”some path/logfile name string”);

Leave a Comment