Class Log4jConfigurator


  • public class Log4jConfigurator
    extends Object
    Configurator used to configure a log4j repository dynamically. Wheter all known loggers or only the explicitly configured loggers are configured is defined by the system property "org.swisspush.gateleen.logging.log4j.showall" which defaults to false. Thus per default only the loggers are modified that have been explicitly configured to the log4j system (typically via a log4j configuration file such as log4j.properties).
    Author:
    schwabmar
    See Also:
    SYS_PROP_SHOW_ALL
    • Field Detail

      • SYS_PROP_SHOW_ALL

        public static final String SYS_PROP_SHOW_ALL
        Name of the "show all loggers" system property.
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static Log4jConfigurator getInstance()
        Gets the one-and-only instance of the class Log4jConfigurator.
        Returns:
        Instance.
      • getLoggers

        public List<String> getLoggers()
        Retrieves all loggers from the log4j repository. Dependent on the flag showAll, this method either returns only the direct configured loggers or all known loggers.
        Returns:
        List of java.lang.String containing all logger names.
        See Also:
        SYS_PROP_SHOW_ALL
      • getLoggersSorted

        public List<String> getLoggersSorted()
        Retrieves all loggers from the log4j repository. Dependent on the flag showAll, this method either returns only the direct configured loggers or all known loggers.
        Returns:
        Sorted list of java.lang.String containing all logger names.
        See Also:
        SYS_PROP_SHOW_ALL
      • getLevel

        public org.apache.log4j.Level getLevel​(String logger)
                                        throws IllegalArgumentException
        Gets a logger's actual level.
        Parameters:
        logger - The logger.
        Returns:
        The logger's level or null if no level was directly set on the logger.
        Throws:
        IllegalArgumentException - In case the logger isn't known.
      • getEffectiveLevel

        public org.apache.log4j.Level getEffectiveLevel​(String logger)
                                                 throws IllegalArgumentException
        Gets a logger's effective level thus either the direct level or the inherited level from it's parent logger.
        Parameters:
        logger - The logger.
        Returns:
        The logger's effective level.
        Throws:
        IllegalArgumentException - In case the logger isn't known.
      • setLoggerLevel

        public void setLoggerLevel​(String logger,
                                   String level)
                            throws IllegalArgumentException
        Sets or deletes a logger's new level.
        Parameters:
        logger - Name of the logger to set.
        level - Level to set the logger to.
        Throws:
        IllegalArgumentException - In case the logger isn't known.