Class Configurator
- java.lang.Object
-
- org.apache.logging.log4j.core.config.Configurator
-
public final class Configurator extends java.lang.ObjectInitializes 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.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateConfigurator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static Log4jContextFactorygetFactory()static LoggerContextinitialize(java.lang.ClassLoader loader, Configuration configuration)Initializes the Logging Context.static LoggerContextinitialize(java.lang.ClassLoader loader, Configuration configuration, java.lang.Object externalContext)Initializes the Logging Context.static LoggerContextinitialize(java.lang.ClassLoader loader, ConfigurationSource source)Initializes the Logging Context.static LoggerContextinitialize(java.lang.ClassLoader loader, ConfigurationSource source, java.lang.Object externalContext)Initializes the Logging Context.static LoggerContextinitialize(java.lang.String name, java.lang.ClassLoader loader, java.lang.String configLocation)Initializes the Logging Context.static LoggerContextinitialize(java.lang.String name, java.lang.ClassLoader loader, java.lang.String configLocation, java.lang.Object externalContext)Initializes the Logging Context.static LoggerContextinitialize(java.lang.String name, java.lang.ClassLoader loader, java.net.URI configLocation)Initializes the Logging Context.static LoggerContextinitialize(java.lang.String name, java.lang.ClassLoader loader, java.net.URI configLocation, java.lang.Object externalContext)Initializes the Logging Context.static LoggerContextinitialize(java.lang.String name, java.lang.ClassLoader loader, java.net.URI configLocation, java.util.Map.Entry<java.lang.String,java.lang.Object> entry)Initializes the Logging Context.static LoggerContextinitialize(java.lang.String name, java.lang.ClassLoader loader, java.util.List<java.net.URI> configLocations, java.lang.Object externalContext)static LoggerContextinitialize(java.lang.String name, java.lang.String configLocation)Initializes the Logging Context.static LoggerContextinitialize(Configuration configuration)Initializes the Logging Context.static voidreconfigure()Reload the existing reconfiguration.static voidreconfigure(java.net.URI uri)Reconfigure with a potentially new configuration.static voidreconfigure(Configuration configuration)Reconfigure using an already constructed Configuration.static voidsetAllLevels(java.lang.String parentLogger, Level level)Sets the levels ofparentLoggerand all 'child' loggers to the givenlevel.static voidsetLevel(java.lang.Class<?> clazz, Level level)Sets a logger's level.static voidsetLevel(java.lang.String loggerName, java.lang.String level)Sets a logger's level.static voidsetLevel(java.lang.String loggerName, Level level)Sets a logger's level.private static booleansetLevel(java.lang.String loggerName, Level level, Configuration config)static voidsetLevel(java.util.Map<java.lang.String,Level> levelMap)Sets logger levels.private static booleansetLevel(LoggerConfig loggerConfig, Level level)private static voidsetLevel(LoggerContext loggerContext, java.lang.String loggerName, Level level)static LoggersetLevel(Logger logger, Level level)Sets a logger's level.static voidsetRootLevel(Level level)Sets the root logger's level.private static voidsetRootLevel(Level level, LoggerContext loggerContext)static voidshutdown(LoggerContext ctx)Shuts down the given logger context.static booleanshutdown(LoggerContext ctx, long timeout, java.util.concurrent.TimeUnit timeUnit)Shuts down the given logger context.
-
-
-
Field Detail
-
FQCN
private static final java.lang.String FQCN
-
LOGGER
private static final Logger LOGGER
-
-
Method Detail
-
getFactory
private static Log4jContextFactory getFactory()
-
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.net.URI configLocation, java.util.Map.Entry<java.lang.String,java.lang.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(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.
-
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(java.net.URI uri)
Reconfigure with a potentially new configuration.- Parameters:
uri- The location of the configuration.- Since:
- 2.12.0
-
setAllLevels
public static void setAllLevels(java.lang.String parentLogger, Level level)Sets the levels ofparentLoggerand all 'child' loggers to the givenlevel.- Parameters:
parentLogger- the parent loggerlevel- the new level
-
setLevel
public static Logger setLevel(Logger logger, Level level)
Sets a logger's level.- Parameters:
logger- the loggerlevel- the new level- Returns:
- the given logger
-
setLevel
public static void setLevel(java.lang.Class<?> clazz, Level level)Sets a logger's level.- Parameters:
clazz- the loggerlevel- the new level
-
setLevel
private static boolean setLevel(LoggerConfig loggerConfig, Level level)
-
setLevel
private static void setLevel(LoggerContext loggerContext, java.lang.String loggerName, Level 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 namelevel- the new level
-
setLevel
public static void setLevel(java.lang.String loggerName, java.lang.String level)Sets a logger's level.- Parameters:
loggerName- the logger namelevel- the new level
-
setLevel
private static boolean setLevel(java.lang.String loggerName, Level level, Configuration config)
-
setRootLevel
public static void setRootLevel(Level level)
Sets the root logger's level.- Parameters:
level- the new level
-
setRootLevel
private static void setRootLevel(Level level, LoggerContext loggerContext)
-
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 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:
LoggerContext.stop(long, TimeUnit)
-
-