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, Piotr P. Karwasz, Dhruv Rastogi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLoggingSystemFactorythat returnsLog4J2LoggingSystemif possible.Nested classes/interfaces inherited from class AbstractLoggingSystem
AbstractLoggingSystem.LogLevels<T> -
Field Summary
Fields inherited from class AbstractLoggingSystem
CONFIGURATION_COMPARATORFields inherited from class LoggingSystem
EXPECT_CORRELATION_ID_PROPERTY, NONE, ROOT_LOGGER_NAME, SYSTEM_PROPERTY -
Method Summary
Modifier and TypeMethodDescriptionvoidReset the logging system to be limit output.voidcleanUp()Clean up the logging system.protected StringReturn the default log correlation pattern ornullif log correlation patterns are not supported.static @Nullable EnvironmentgetEnvironment(@Nullable LoggerContext loggerContext) Get the SpringEnvironmentattached to the givenLoggerContextornullif 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.Return any self initialization config that has been applied.Returns aRunnablethat can handle shutdown of this logging system when the JVM exits.Return any spring specific initialization config that should be applied.protected String[]Return the standard config locations for this system.Returns a set of theLogLevelsthat are actually supported by the logging system.getSystemProperties(ConfigurableEnvironment environment) Return theLoggingSystemPropertiesthat should be applied.voidinitialize(LoggingInitializationContext initializationContext, @Nullable String configLocation, @Nullable LogFile logFile) Fully initialize the logging system.protected voidloadConfiguration(LoggingInitializationContext initializationContext, String location, @Nullable LogFile logFile) Load a specific configuration.protected voidloadDefaults(LoggingInitializationContext initializationContext, @Nullable LogFile logFile) Load sensible defaults for the logging system.protected voidreinitialize(LoggingInitializationContext initializationContext) Reinitialize the logging system if required.voidsetLogLevel(@Nullable String loggerName, @Nullable LogLevel logLevel) Sets the logging level for a given logger.Methods inherited from class AbstractLoggingSystem
applySystemProperties, getClassLoader, getDefaultValueResolver, getPackagedConfigFile, getSpringConfigLocationsMethods inherited from class LoggingSystem
get
-
Method Details
-
getSystemProperties
Description copied from class:LoggingSystemReturn theLoggingSystemPropertiesthat should be applied.- Overrides:
getSystemPropertiesin classLoggingSystem- Parameters:
environment- theConfigurableEnvironmentused to obtain value- Returns:
- the
LoggingSystemPropertiesto apply
-
getStandardConfigLocations
Description copied from class:AbstractLoggingSystemReturn the standard config locations for this system.- Specified by:
getStandardConfigLocationsin classAbstractLoggingSystem- Returns:
- the standard config locations
- See Also:
-
getSelfInitializationConfig
Description copied from class:AbstractLoggingSystemReturn any self initialization config that has been applied. By default this method checksAbstractLoggingSystem.getStandardConfigLocations()and assumes that any file that exists will have been applied.- Overrides:
getSelfInitializationConfigin classAbstractLoggingSystem- Returns:
- the self initialization config or
null
-
getSpringInitializationConfig
Description copied from class:AbstractLoggingSystemReturn any spring specific initialization config that should be applied. By default this method checksAbstractLoggingSystem.getSpringConfigLocations().- Overrides:
getSpringInitializationConfigin classAbstractLoggingSystem- Returns:
- the spring initialization config or
null
-
beforeInitialize
public void beforeInitialize()Description copied from class:LoggingSystemReset 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:
beforeInitializein classAbstractLoggingSystem
-
initialize
public void initialize(LoggingInitializationContext initializationContext, @Nullable String configLocation, @Nullable LogFile logFile) Description copied from class:LoggingSystemFully initialize the logging system.- Overrides:
initializein classAbstractLoggingSystem- Parameters:
initializationContext- the logging initialization contextconfigLocation- a log configuration location ornullif default initialization is requiredlogFile- the log output file that should be written ornullfor console only output
-
loadDefaults
protected void loadDefaults(LoggingInitializationContext initializationContext, @Nullable LogFile logFile) Description copied from class:AbstractLoggingSystemLoad sensible defaults for the logging system.- Specified by:
loadDefaultsin classAbstractLoggingSystem- Parameters:
initializationContext- the logging initialization contextlogFile- the file to load ornullif no log file is to be written
-
loadConfiguration
protected void loadConfiguration(LoggingInitializationContext initializationContext, String location, @Nullable LogFile logFile) Description copied from class:AbstractLoggingSystemLoad a specific configuration.- Specified by:
loadConfigurationin classAbstractLoggingSystem- Parameters:
initializationContext- the logging initialization contextlocation- the location of the configuration to load (nevernull)logFile- the file to load ornullif no log file is to be written
-
reinitialize
Description copied from class:AbstractLoggingSystemReinitialize 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:
reinitializein classAbstractLoggingSystem- Parameters:
initializationContext- the logging initialization context
-
getSupportedLogLevels
Description copied from class:LoggingSystemReturns a set of theLogLevelsthat are actually supported by the logging system.- Overrides:
getSupportedLogLevelsin classLoggingSystem- Returns:
- the supported levels
-
setLogLevel
Description copied from class:LoggingSystemSets the logging level for a given logger.- Overrides:
setLogLevelin classLoggingSystem- Parameters:
loggerName- the name of the logger to set (nullcan be used for the root logger).logLevel- the log level (nullcan be used to remove any custom level for the logger and use the default configuration instead)
-
getLoggerConfigurations
Description copied from class:LoggingSystemReturns a collection of the current configuration for all aLoggingSystem's loggers.- Overrides:
getLoggerConfigurationsin classLoggingSystem- Returns:
- the current configurations
-
getLoggerConfiguration
Description copied from class:LoggingSystemReturns the current configuration for aLoggingSystem's logger.- Overrides:
getLoggerConfigurationin classLoggingSystem- Parameters:
loggerName- the name of the logger- Returns:
- the current configuration
-
getShutdownHandler
Description copied from class:LoggingSystemReturns aRunnablethat can handle shutdown of this logging system when the JVM exits. The default implementation returnsnull, indicating that no shutdown is required.- Overrides:
getShutdownHandlerin classLoggingSystem- Returns:
- the shutdown handler, or
null
-
cleanUp
public void cleanUp()Description copied from class:LoggingSystemClean up the logging system. The default implementation does nothing. Subclasses should override this method to perform any logging system-specific cleanup.- Overrides:
cleanUpin classLoggingSystem
-
getDefaultLogCorrelationPattern
Description copied from class:AbstractLoggingSystemReturn the default log correlation pattern ornullif log correlation patterns are not supported.- Overrides:
getDefaultLogCorrelationPatternin classAbstractLoggingSystem- Returns:
- the default log correlation pattern
-
getEnvironment
Get the SpringEnvironmentattached to the givenLoggerContextornullif no environment is available.- Parameters:
loggerContext- the logger context- Returns:
- the Spring
Environmentornull - Since:
- 3.0.0
-