Class Configurator
java.lang.Object
org.apache.logging.log4j.core.config.Configurator
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
Modifier and TypeMethodDescriptionstatic LoggerContext
initialize
(ClassLoader loader, Configuration configuration) Initializes the Logging Context.static LoggerContext
initialize
(ClassLoader loader, Configuration configuration, Object externalContext) Initializes the Logging Context.static LoggerContext
initialize
(ClassLoader loader, ConfigurationSource source) Initializes the Logging Context.static LoggerContext
initialize
(ClassLoader loader, ConfigurationSource source, Object externalContext) Initializes the Logging Context.static LoggerContext
initialize
(String name, ClassLoader loader, String configLocation) Initializes the Logging Context.static LoggerContext
initialize
(String name, ClassLoader loader, String configLocation, Object externalContext) Initializes the Logging Context.static LoggerContext
initialize
(String name, ClassLoader loader, URI configLocation) Initializes the Logging Context.static LoggerContext
initialize
(String name, ClassLoader loader, URI configLocation, Object externalContext) Initializes the Logging Context.static LoggerContext
initialize
(String name, ClassLoader loader, URI configLocation, Map.Entry<String, Object> entry) Initializes the Logging Context.static LoggerContext
initialize
(String name, ClassLoader loader, List<URI> configLocations, Object externalContext) static LoggerContext
initialize
(String name, String configLocation) Initializes the Logging Context.static LoggerContext
initialize
(Configuration configuration) Initializes the Logging Context.static void
Reload the existing reconfiguration.static void
reconfigure
(URI uri) Reconfigure with a potentially new configuration.static void
reconfigure
(Configuration configuration) Reconfigure using an already constructed Configuration.static void
setAllLevels
(String parentLogger, Level level) Sets the levels ofparentLogger
and all 'child' loggers to the givenlevel
.static void
Sets a logger's level.static void
Sets a logger's level.static void
Sets a logger's level.static void
Sets logger levels.static Logger
Sets a logger's level.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, TimeUnit timeUnit) Shuts down the given logger context.
-
Method Details
-
initialize
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
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
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, ClassLoader loader, URI configLocation, Map.Entry<String, Object> entry) 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).entry
- The external context entry to be attached to the LoggerContext- Returns:
- The LoggerContext.
-
initialize
public static LoggerContext initialize(String name, ClassLoader loader, List<URI> configLocations, Object externalContext) -
initialize
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
Initializes the Logging Context.- Parameters:
configuration
- The Configuration.- Returns:
- The LoggerContext.
-
initialize
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
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
Reconfigure with a potentially new configuration.- Parameters:
uri
- The location of the configuration.- Since:
- 2.12.0
-
setAllLevels
Sets the levels ofparentLogger
and all 'child' loggers to the givenlevel
.- Parameters:
parentLogger
- the parent loggerlevel
- the new level
-
setLevel
Sets a logger's level.- Parameters:
logger
- the loggerlevel
- the new level- Returns:
- the given logger
-
setLevel
Sets a logger's level.- Parameters:
clazz
- the loggerlevel
- the new level
-
setLevel
Sets logger levels.- Parameters:
levelMap
- a levelMap where keys are level names and values are new Levels.
-
setLevel
Sets a logger's level.- Parameters:
loggerName
- the logger namelevel
- the new level
-
setLevel
Sets a logger's level.- Parameters:
loggerName
- the logger namelevel
- the new level
-
setRootLevel
Sets the root logger's level.- Parameters:
level
- the new level
-
shutdown
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
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 waittimeUnit
- the time unit of the timeout argument- Returns:
true
if the logger context terminated andfalse
if the timeout elapsed before termination.- Since:
- 2.7
- See Also:
-