Class LoggingApplicationListener
java.lang.Object
org.springframework.boot.context.logging.LoggingApplicationListener
- All Implemented Interfaces:
EventListener,org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>,org.springframework.context.event.GenericApplicationListener,org.springframework.context.event.SmartApplicationListener,org.springframework.core.Ordered
public class LoggingApplicationListener
extends Object
implements org.springframework.context.event.GenericApplicationListener
An
ApplicationListener that configures the LoggingSystem. If the
environment contains a logging.config property it will be used to bootstrap the
logging system, otherwise a default configuration is used. Regardless, logging levels
will be customized if the environment contains logging.level.* entries and
logging groups can be defined with logging.group.
Debug and trace logging for Spring, Tomcat, Jetty and Hibernate will be enabled when
the environment contains debug or trace properties that aren't set to
"false" (i.e. if you start your application using
java -jar myapp.jar [--debug | --trace]). If you prefer to ignore these
properties you can set parseArgs to false.
By default, log output is only written to the console. If a log file is required, the
logging.file.path and logging.file.name properties can be used.
Some system properties may be set as side effects, and these can be useful if the logging configuration supports placeholders (i.e. log4j or logback):
LOG_FILEis set to the value of path of the log file that should be written (if any).PIDis set to the value of the current process ID if it can be determined.
- Since:
- 2.0.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the Spring property that contains a reference to the logging configuration to load.static final intThe default order for the LoggingApplicationListener.static final StringThe name of theLogFilebean.static final StringThe name of theLoggerGroupsbean.static final StringThe name of theLoggingSystembean.static final StringThe name of the Spring property that controls the registration of a shutdown hook to shut down the logging system when the JVM exits.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()protected voidinitialize(org.springframework.core.env.ConfigurableEnvironment environment, ClassLoader classLoader) Initialize the logging system according to preferences expressed through theEnvironmentand the classpath.protected voidinitializeSpringBootLogging(LoggingSystem system, LogLevel springBootLogging) Initialize loggers based on thespringBootLoggingsetting.voidonApplicationEvent(org.springframework.context.ApplicationEvent event) protected voidsetLogLevels(LoggingSystem system, org.springframework.core.env.ConfigurableEnvironment environment) Set logging levels based on relevantEnvironmentproperties.voidsetOrder(int order) voidsetParseArgs(boolean parseArgs) Sets if initialization arguments should be parsed for debug and trace properties (usually defined from --debug or --trace command line args).voidsetSpringBootLogging(LogLevel springBootLogging) Sets a custom logging level to be used for Spring Boot and related libraries.booleansupportsEventType(org.springframework.core.ResolvableType resolvableType) booleansupportsSourceType(Class<?> sourceType) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecutionMethods inherited from interface org.springframework.context.event.GenericApplicationListener
supportsEventTypeMethods inherited from interface org.springframework.context.event.SmartApplicationListener
getListenerId
-
Field Details
-
DEFAULT_ORDER
public static final int DEFAULT_ORDERThe default order for the LoggingApplicationListener.- See Also:
-
CONFIG_PROPERTY
The name of the Spring property that contains a reference to the logging configuration to load.- See Also:
-
REGISTER_SHUTDOWN_HOOK_PROPERTY
The name of the Spring property that controls the registration of a shutdown hook to shut down the logging system when the JVM exits. -
LOGGING_SYSTEM_BEAN_NAME
The name of theLoggingSystembean.- See Also:
-
LOG_FILE_BEAN_NAME
The name of theLogFilebean.- Since:
- 2.2.0
- See Also:
-
LOGGER_GROUPS_BEAN_NAME
The name of theLoggerGroupsbean.- Since:
- 2.2.0
- See Also:
-
-
Constructor Details
-
LoggingApplicationListener
public LoggingApplicationListener()
-
-
Method Details
-
supportsEventType
public boolean supportsEventType(org.springframework.core.ResolvableType resolvableType) - Specified by:
supportsEventTypein interfaceorg.springframework.context.event.GenericApplicationListener
-
supportsSourceType
- Specified by:
supportsSourceTypein interfaceorg.springframework.context.event.SmartApplicationListener
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent event) - Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
-
initialize
protected void initialize(org.springframework.core.env.ConfigurableEnvironment environment, ClassLoader classLoader) Initialize the logging system according to preferences expressed through theEnvironmentand the classpath.- Parameters:
environment- the environmentclassLoader- the classloader
-
initializeSpringBootLogging
Initialize loggers based on thespringBootLoggingsetting. By default this implementation will pick an appropriate set of loggers to configure based on the level.- Parameters:
system- the logging systemspringBootLogging- the spring boot logging level requested- Since:
- 2.2.0
-
setLogLevels
protected void setLogLevels(LoggingSystem system, org.springframework.core.env.ConfigurableEnvironment environment) Set logging levels based on relevantEnvironmentproperties.- Parameters:
system- the logging systemenvironment- the environment- Since:
- 2.2.0
-
setOrder
public void setOrder(int order) -
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Specified by:
getOrderin interfaceorg.springframework.context.event.SmartApplicationListener
-
setSpringBootLogging
Sets a custom logging level to be used for Spring Boot and related libraries.- Parameters:
springBootLogging- the logging level
-
setParseArgs
public void setParseArgs(boolean parseArgs) Sets if initialization arguments should be parsed for debug and trace properties (usually defined from --debug or --trace command line args). Defaults totrue.- Parameters:
parseArgs- if arguments should be parsed
-