Class Log4jConfigurator


  • public class Log4jConfigurator
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SYS_PROP_SHOW_ALL
      Name of the "show all loggers" system property.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.String> getAppenders​(java.lang.String logger)
      Gets the appenders to a specific logger.
      org.apache.log4j.Level getEffectiveLevel​(java.lang.String logger)
      Gets a logger's effective level thus either the direct level or the inherited level from it's parent logger.
      static Log4jConfigurator getInstance()
      Gets the one-and-only instance of the class Log4jConfigurator.
      org.apache.log4j.Level getLevel​(java.lang.String logger)
      Gets a logger's actual level.
      java.util.List<java.lang.String> getLoggers()
      Retrieves all loggers from the log4j repository.
      java.util.List<java.lang.String> getLoggersSorted()
      Retrieves all loggers from the log4j repository.
      void setLoggerLevel​(java.lang.String logger, java.lang.String level)
      Sets or deletes a logger's new level.
      • Methods inherited from class java.lang.Object

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

      • SYS_PROP_SHOW_ALL

        public static final java.lang.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 java.util.List<java.lang.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 java.util.List<java.lang.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
      • getAppenders

        public java.util.List<java.lang.String> getAppenders​(java.lang.String logger)
                                                      throws java.lang.IllegalArgumentException
        Gets the appenders to a specific logger.
        Parameters:
        logger - A logger's name.
        Returns:
        List of java.lang.String containing all appender names.
        Throws:
        java.lang.IllegalArgumentException - In case the logger isn't known.
      • getLevel

        public org.apache.log4j.Level getLevel​(java.lang.String logger)
                                        throws java.lang.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:
        java.lang.IllegalArgumentException - In case the logger isn't known.
      • getEffectiveLevel

        public org.apache.log4j.Level getEffectiveLevel​(java.lang.String logger)
                                                 throws java.lang.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:
        java.lang.IllegalArgumentException - In case the logger isn't known.
      • setLoggerLevel

        public void setLoggerLevel​(java.lang.String logger,
                                   java.lang.String level)
                            throws java.lang.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:
        java.lang.IllegalArgumentException - In case the logger isn't known.