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:

    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 is used, following the above search order to find it.
    The directory for storing logs. If not specified, logs are stored in the JMRI preferences directory.
    • Constructor Summary

      Constructor Description
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (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 some default exception handlers (to feed the logs?)
      • 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.

        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 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.

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