Package apps.util

Class Log4JUtil


  • public class Log4JUtil
    extends java.lang.Object
    Common utility methods for working with Log4J.

    Two system properties influence how logging is configured in JMRI:

    jmri.log
    The logging control file. If this file is not an absolute path, this file is searched for in the following order:
    1. JMRI settings directory
    2. JMRI installation (program) directory
    If this property is not specified, the logging control file default_lcf.xml is used, following the above search order to find it.
    jmri.log.path
    The directory for storing logs. If not specified, logs are stored in the JMRI preferences directory.

    See also jmri.util.TestingLoggerConfiguration in the Test code for Tests Logging Setup.

    • Constructor Summary

      Constructors 
      Constructor Description
      Log4JUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getLoggingConfig​(java.lang.String logFileLocation)  
      (package private) static void initializeJavaUtilLogging()  
      (package private) static void initLog4J​(java.lang.String logFile)
      Initialize Log4J.
      static void initLogging()
      Initialize logging from a default control file.
      static void initLogging​(java.lang.String controlfile)
      Initialize logging, specifying a control file.
      static java.lang.String startupInfo​(java.lang.String program)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • initLogging

        public static void initLogging()
        Initialize logging from a default control file.

        Primary functions:

        • Initialize the JMRI System Console.
        • Set up the slf4j j.u.logging to log4J bridge.
        • Start log4j.
        • Initialize a default exception handler.
      • initLogging

        public static void initLogging​(@Nonnull
                                       java.lang.String controlfile)
        Initialize logging, specifying a control file.

        Generally, only used for unit testing. Much better to use allow this class to find the control file using a set of conventions.

        Parameters:
        controlfile - the logging control file
      • initLog4J

        static void initLog4J​(@Nonnull
                              java.lang.String logFile)
        Initialize Log4J.

        Use the logging control file specified in the jmri.log property or, if none, the default_lcf.xml file. If the file is absolute and cannot be found, look for the file first in the settings directory and then in the installation directory.

        Parameters:
        logFile - the logging control file
        See Also:
        FileUtil.getPreferencesPath(), FileUtil.getProgramPath()