Class Log4J2LoggingSystem
java.lang.Object
org.springframework.boot.logging.LoggingSystem
org.springframework.boot.logging.AbstractLoggingSystem
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
LoggingSystem
for Log4j 2.- Since:
- 1.2.0
- Author:
- Daniel Fullarton, Andy Wilkinson, Alexander Heusingfeld, Ben Hale, Ralph Goers
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
LoggingSystemFactory
that returnsLog4J2LoggingSystem
if possible.Nested classes/interfaces inherited from class org.springframework.boot.logging.AbstractLoggingSystem
AbstractLoggingSystem.LogLevels<T>
-
Field Summary
Fields inherited from class org.springframework.boot.logging.AbstractLoggingSystem
CONFIGURATION_COMPARATOR
Fields inherited from class org.springframework.boot.logging.LoggingSystem
NONE, ROOT_LOGGER_NAME, SYSTEM_PROPERTY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Reset the logging system to be limit output.void
cleanUp()
Clean up the logging system.static Environment
getEnvironment
(org.apache.logging.log4j.core.LoggerContext loggerContext) Get the SpringEnvironment
attached to the givenLoggerContext
ornull
if no environment is available.getLoggerConfiguration
(String loggerName) Returns the current configuration for aLoggingSystem
's logger.Returns a collection of the current configuration for all aLoggingSystem
's loggers.Returns aRunnable
that can handle shutdown of this logging system when the JVM exits.protected String[]
Return the standard config locations for this system.Returns a set of theLogLevels
that are actually supported by the logging system.void
initialize
(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) Fully initialize the logging system.protected boolean
isClassAvailable
(String className) protected void
loadConfiguration
(String location, LogFile logFile, List<String> overrides) Load the configuration from the givenlocation
, creating a composite using the configuration from the givenoverrides
.protected void
loadConfiguration
(LoggingInitializationContext initializationContext, String location, LogFile logFile) Load a specific configuration.protected void
loadDefaults
(LoggingInitializationContext initializationContext, LogFile logFile) Load sensible defaults for the logging system.protected void
reinitialize
(LoggingInitializationContext initializationContext) Reinitialize the logging system if required.void
setLogLevel
(String loggerName, LogLevel logLevel) Sets the logging level for a given logger.Methods inherited from class org.springframework.boot.logging.AbstractLoggingSystem
applySystemProperties, getClassLoader, getPackagedConfigFile, getSelfInitializationConfig, getSpringConfigLocations, getSpringInitializationConfig
Methods inherited from class org.springframework.boot.logging.LoggingSystem
get, getSystemProperties
-
Constructor Details
-
Log4J2LoggingSystem
-
-
Method Details
-
getStandardConfigLocations
Description copied from class:AbstractLoggingSystem
Return the standard config locations for this system.- Specified by:
getStandardConfigLocations
in classAbstractLoggingSystem
- Returns:
- the standard config locations
- See Also:
-
isClassAvailable
-
beforeInitialize
public void beforeInitialize()Description copied from class:LoggingSystem
Reset the logging system to be limit output. This method may be called beforeLoggingSystem.initialize(LoggingInitializationContext, String, LogFile)
to reduce logging noise until the system has been fully initialized.- Overrides:
beforeInitialize
in classAbstractLoggingSystem
-
initialize
public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) Description copied from class:LoggingSystem
Fully initialize the logging system.- Overrides:
initialize
in classAbstractLoggingSystem
- Parameters:
initializationContext
- the logging initialization contextconfigLocation
- a log configuration location ornull
if default initialization is requiredlogFile
- the log output file that should be written ornull
for console only output
-
loadDefaults
Description copied from class:AbstractLoggingSystem
Load sensible defaults for the logging system.- Specified by:
loadDefaults
in classAbstractLoggingSystem
- Parameters:
initializationContext
- the logging initialization contextlogFile
- the file to load ornull
if no log file is to be written
-
loadConfiguration
protected void loadConfiguration(LoggingInitializationContext initializationContext, String location, LogFile logFile) Description copied from class:AbstractLoggingSystem
Load a specific configuration.- Specified by:
loadConfiguration
in classAbstractLoggingSystem
- Parameters:
initializationContext
- the logging initialization contextlocation
- the location of the configuration to load (nevernull
)logFile
- the file to load ornull
if no log file is to be written
-
loadConfiguration
Load the configuration from the givenlocation
, creating a composite using the configuration from the givenoverrides
.- Parameters:
location
- the locationlogFile
- log file configurationoverrides
- the overriding locations- Since:
- 2.6.0
-
reinitialize
Description copied from class:AbstractLoggingSystem
Reinitialize the logging system if required. Called whenAbstractLoggingSystem.getSelfInitializationConfig()
is used and the log file hasn't changed. May be used to reload configuration (for example to pick up additional System properties).- Overrides:
reinitialize
in classAbstractLoggingSystem
- Parameters:
initializationContext
- the logging initialization context
-
getSupportedLogLevels
Description copied from class:LoggingSystem
Returns a set of theLogLevels
that are actually supported by the logging system.- Overrides:
getSupportedLogLevels
in classLoggingSystem
- Returns:
- the supported levels
-
setLogLevel
Description copied from class:LoggingSystem
Sets the logging level for a given logger.- Overrides:
setLogLevel
in classLoggingSystem
- Parameters:
loggerName
- the name of the logger to set (null
can be used for the root logger).logLevel
- the log level (null
can be used to remove any custom level for the logger and use the default configuration instead)
-
getLoggerConfigurations
Description copied from class:LoggingSystem
Returns a collection of the current configuration for all aLoggingSystem
's loggers.- Overrides:
getLoggerConfigurations
in classLoggingSystem
- Returns:
- the current configurations
-
getLoggerConfiguration
Description copied from class:LoggingSystem
Returns the current configuration for aLoggingSystem
's logger.- Overrides:
getLoggerConfiguration
in classLoggingSystem
- Parameters:
loggerName
- the name of the logger- Returns:
- the current configuration
-
getShutdownHandler
Description copied from class:LoggingSystem
Returns aRunnable
that can handle shutdown of this logging system when the JVM exits. The default implementation returnsnull
, indicating that no shutdown is required.- Overrides:
getShutdownHandler
in classLoggingSystem
- Returns:
- the shutdown handler, or
null
-
cleanUp
public void cleanUp()Description copied from class:LoggingSystem
Clean up the logging system. The default implementation does nothing. Subclasses should override this method to perform any logging system-specific cleanup.- Overrides:
cleanUp
in classLoggingSystem
-
getEnvironment
Get the SpringEnvironment
attached to the givenLoggerContext
ornull
if no environment is available.- Parameters:
loggerContext
- the logger context- Returns:
- the Spring
Environment
ornull
- Since:
- 3.0.0
-