Class Configurator


  • public final class Configurator
    extends 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 Detail

      • initialize

        public static LoggerContext initialize​(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​(ClassLoader loader,
                                               ConfigurationSource source,
                                               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​(String name,
                                               ClassLoader loader,
                                               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​(String name,
                                               ClassLoader loader,
                                               String configLocation,
                                               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​(String name,
                                               ClassLoader loader,
                                               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​(String name,
                                               ClassLoader loader,
                                               URI configLocation,
                                               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​(String name,
                                               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​(ClassLoader loader,
                                               Configuration configuration)
        Initializes the Logging Context.
        Parameters:
        loader - The ClassLoader.
        configuration - The Configuration.
        Returns:
        The LoggerContext.
      • initialize

        public static LoggerContext initialize​(ClassLoader loader,
                                               Configuration configuration,
                                               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.
      • reconfigure

        public static void reconfigure​(Configuration configuration)
        Reconfigure using an already constructed Configuration.
        Parameters:
        configuration - The configuration.
        Since:
        2.13.0
      • reconfigure

        public static void reconfigure()
        Reload the existing reconfiguration.
        Since:
        2.12.0
      • reconfigure

        public static void reconfigure​(URI uri)
        Reconfigure with a potentially new configuration.
        Parameters:
        uri - The location of the configuration.
        Since:
        2.12.0
      • setAllLevels

        public static void setAllLevels​(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​(Map<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​(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,
                                       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)