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 LoggerContextinitialize(ClassLoader loader, Configuration configuration) Initializes the Logging Context.static LoggerContextinitialize(ClassLoader loader, Configuration configuration, Object externalContext) Initializes the Logging Context.static LoggerContextinitialize(ClassLoader loader, ConfigurationSource source) Initializes the Logging Context.static LoggerContextinitialize(ClassLoader loader, ConfigurationSource source, Object externalContext) Initializes the Logging Context.static LoggerContextinitialize(String name, ClassLoader loader, String configLocation) Initializes the Logging Context.static LoggerContextinitialize(String name, ClassLoader loader, String configLocation, Object externalContext) Initializes the Logging Context.static LoggerContextinitialize(String name, ClassLoader loader, URI configLocation) Initializes the Logging Context.static LoggerContextinitialize(String name, ClassLoader loader, URI configLocation, Object externalContext) Initializes the Logging Context.static LoggerContextinitialize(String name, ClassLoader loader, URI configLocation, Map.Entry<String, Object> entry) Initializes the Logging Context.static LoggerContextinitialize(String name, ClassLoader loader, List<URI> configLocations, Object externalContext) static LoggerContextinitialize(String name, String configLocation) Initializes the Logging Context.static LoggerContextinitialize(Configuration configuration) Initializes the Logging Context.static voidReload the existing reconfiguration.static voidreconfigure(URI uri) Reconfigure with a potentially new configuration.static voidreconfigure(Configuration configuration) Reconfigure using an already constructed Configuration.static voidsetAllLevels(String parentLogger, Level level) Sets the levels ofparentLoggerand all 'child' loggers to the givenlevel.static voidSets a logger's level.static voidSets a logger's level.static voidSets a logger's level.static voidSets logger levels.static LoggerSets a logger's level.static voidsetRootLevel(Level level) Sets the root logger's level.static voidshutdown(LoggerContext ctx) Shuts down the given logger context.static booleanshutdown(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 ofparentLoggerand 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:
trueif the logger context terminated andfalseif the timeout elapsed before termination.- Since:
- 2.7
- See Also:
-