Class Configurator


  • public final class Configurator
    extends java.lang.Object
    Initializes and configure the Logging system. This class provides several ways to construct a LoggerContext using the location of a configuration file, a context name, and various optional parameters.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static LoggerContext initialize​(java.lang.ClassLoader loader, Configuration configuration)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.ClassLoader loader, Configuration configuration, java.lang.Object externalContext)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.ClassLoader loader, ConfigurationSource source)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.ClassLoader loader, ConfigurationSource source, java.lang.Object externalContext)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.String name, java.lang.ClassLoader loader, java.lang.String configLocation)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.String name, java.lang.ClassLoader loader, java.lang.String configLocation, java.lang.Object externalContext)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.String name, java.lang.ClassLoader loader, java.net.URI configLocation)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.String name, java.lang.ClassLoader loader, java.net.URI configLocation, java.lang.Object externalContext)
      Initializes the Logging Context.
      static LoggerContext initialize​(java.lang.String name, java.lang.ClassLoader loader, java.util.List<java.net.URI> configLocations, java.lang.Object externalContext)  
      static LoggerContext initialize​(java.lang.String name, java.lang.String configLocation)
      Initializes the Logging Context.
      static LoggerContext initialize​(Configuration configuration)
      Initializes the Logging Context.
      static void setAllLevels​(java.lang.String parentLogger, Level level)
      Sets the levels of parentLogger and all 'child' loggers to the given level.
      static void setLevel​(java.lang.String loggerName, Level level)
      Sets a logger's level.
      static void setLevel​(java.util.Map<java.lang.String,​Level> levelMap)
      Sets logger levels.
      static void setRootLevel​(Level level)
      Sets the root logger's level.
      static void shutdown​(LoggerContext ctx)
      Shuts down the given logger context.
      static boolean shutdown​(LoggerContext ctx, long timeout, java.util.concurrent.TimeUnit timeUnit)
      Shuts down the given logger context.
      • Methods inherited from class java.lang.Object

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

      • initialize

        public static LoggerContext initialize​(java.lang.ClassLoader loader,
                                               ConfigurationSource source)
        Initializes the Logging Context.
        Parameters:
        loader - The ClassLoader for the Context (or null).
        source - The InputSource for the configuration.
        Returns:
        The LoggerContext.
      • initialize

        public static LoggerContext initialize​(java.lang.ClassLoader loader,
                                               ConfigurationSource source,
                                               java.lang.Object externalContext)
        Initializes the Logging Context.
        Parameters:
        loader - The ClassLoader for the Context (or null).
        source - The InputSource for the configuration.
        externalContext - The external context to be attached to the LoggerContext.
        Returns:
        The LoggerContext.
      • initialize

        public static LoggerContext initialize​(java.lang.String name,
                                               java.lang.ClassLoader loader,
                                               java.lang.String configLocation)
        Initializes the Logging Context.
        Parameters:
        name - The Context name.
        loader - The ClassLoader for the Context (or null).
        configLocation - The configuration for the logging context.
        Returns:
        The LoggerContext or null if an error occurred (check the status logger).
      • initialize

        public static LoggerContext initialize​(java.lang.String name,
                                               java.lang.ClassLoader loader,
                                               java.lang.String configLocation,
                                               java.lang.Object externalContext)
        Initializes the Logging Context.
        Parameters:
        name - The Context name.
        loader - The ClassLoader for the Context (or null).
        configLocation - The configuration for the logging context (or null, or blank).
        externalContext - The external context to be attached to the LoggerContext
        Returns:
        The LoggerContext or null if an error occurred (check the status logger).
      • initialize

        public static LoggerContext initialize​(java.lang.String name,
                                               java.lang.ClassLoader loader,
                                               java.net.URI configLocation)
        Initializes the Logging Context.
        Parameters:
        name - The Context name.
        loader - The ClassLoader for the Context (or null).
        configLocation - The configuration for the logging context.
        Returns:
        The LoggerContext.
      • initialize

        public static LoggerContext initialize​(java.lang.String name,
                                               java.lang.ClassLoader loader,
                                               java.net.URI configLocation,
                                               java.lang.Object externalContext)
        Initializes the Logging Context.
        Parameters:
        name - The Context name.
        loader - The ClassLoader for the Context (or null).
        configLocation - The configuration for the logging context (or null).
        externalContext - The external context to be attached to the LoggerContext
        Returns:
        The LoggerContext.
      • initialize

        public static LoggerContext initialize​(java.lang.String name,
                                               java.lang.ClassLoader loader,
                                               java.util.List<java.net.URI> configLocations,
                                               java.lang.Object externalContext)
      • initialize

        public static LoggerContext initialize​(java.lang.String name,
                                               java.lang.String configLocation)
        Initializes the Logging Context.
        Parameters:
        name - The Context name.
        configLocation - The configuration for the logging context.
        Returns:
        The LoggerContext or null if an error occurred (check the status logger).
      • initialize

        public static LoggerContext initialize​(Configuration configuration)
        Initializes the Logging Context.
        Parameters:
        configuration - The Configuration.
        Returns:
        The LoggerContext.
      • initialize

        public static LoggerContext initialize​(java.lang.ClassLoader loader,
                                               Configuration configuration)
        Initializes the Logging Context.
        Parameters:
        loader - The ClassLoader.
        configuration - The Configuration.
        Returns:
        The LoggerContext.
      • initialize

        public static LoggerContext initialize​(java.lang.ClassLoader loader,
                                               Configuration configuration,
                                               java.lang.Object externalContext)
        Initializes the Logging Context.
        Parameters:
        loader - The ClassLoader.
        configuration - The Configuration.
        externalContext - - The external context to be attached to the LoggerContext.
        Returns:
        The LoggerContext.
      • setAllLevels

        public static void setAllLevels​(java.lang.String parentLogger,
                                        Level level)
        Sets the levels of parentLogger and all 'child' loggers to the given level.
        Parameters:
        parentLogger - the parent logger
        level - the new level
      • setLevel

        public static void setLevel​(java.util.Map<java.lang.String,​Level> levelMap)
        Sets logger levels.
        Parameters:
        levelMap - a levelMap where keys are level names and values are new Levels.
      • setLevel

        public static void setLevel​(java.lang.String loggerName,
                                    Level level)
        Sets a logger's level.
        Parameters:
        loggerName - the logger name
        level - the new level
      • setRootLevel

        public static void setRootLevel​(Level level)
        Sets the root logger's level.
        Parameters:
        level - the new level
      • shutdown

        public static void shutdown​(LoggerContext ctx)
        Shuts down the given logger context. This request does not wait for Log4j tasks to complete.

        Log4j starts threads to perform certain actions like file rollovers; calling this method will not wait until the rollover thread is done. When this method returns, these tasks' status are undefined, the tasks may be done or not.

        Parameters:
        ctx - the logger context to shut down, may be null.
      • shutdown

        public static boolean shutdown​(LoggerContext ctx,
                                       long timeout,
                                       java.util.concurrent.TimeUnit timeUnit)
        Shuts down the given logger context.

        Log4j can start threads to perform certain actions like file rollovers; calling this method with a positive timeout will block until the rollover thread is done.

        Parameters:
        ctx - the logger context to shut down, may be null.
        timeout - the maximum time to wait
        timeUnit - the time unit of the timeout argument
        Returns:
        true if the logger context terminated and false if the timeout elapsed before termination.
        Since:
        2.7
        See Also:
        LoggerContext.stop(long, TimeUnit)