Class Log4j2CliConfiguration

java.lang.Object
com.randomnoun.common.log4j2.Log4j2CliConfiguration

public class Log4j2CliConfiguration extends Object
Configures log4j for command-line interface programs.

This class configured the log4j2 (two!) framework, using log4j1 (one!) properties.

It uses a modified Log4j1ConfigurationParser (from the log4j2 framework) to do this, which maps some well-known log4j1 appenders to log4j2 appenders, and does a pretty ham-fisted job of everything else.

By default, everything's sent to stdout, using the following log4j initialisation properties:

log4j.rootCategory=DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p %c - %m %n

log4j.logger.org.springframework=INFO

# log4j.appender.FILE=com.randomnoun.common.log4j.CustomRollingFileAppender
# log4j.appender.FILE.File=c:\\another.log
# log4j.appender.FILE.MaxBackupIndex=100
# log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
# log4j.appender.FILE.layout.ConversionPattern=%d{dd/MM/yy HH:mm:ss.SSS} %-5p %c - %m %n
   

with an optional line prefix before the %d{ABSOLUTE} in the ConversionPattern.

Author:
knoxg
See Also:
  • Constructor Details

  • Method Details

    • init

      public void init(String logFormatPrefix, Properties override)
      Initialise log4j.

      The properties file supplied is in log4j format.

      Parameters:
      logFormatPrefix - a string prefixed to each log. Useful for program identifiers; e.g. "[programName] "
      override - if non-null, additional log4j properties. Any properties contained in this object will override the defaults.