public class LoggingApplicationListener
extends java.lang.Object
implements org.springframework.context.event.GenericApplicationListener
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_FILE is set to the value of path of the log file that should be written
(if any).PID is set to the value of the current process ID if it can be determined.
LoggingSystem.get(ClassLoader)| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CONFIG_PROPERTY
The name of the Spring property that contains a reference to the logging
configuration to load.
|
static int |
DEFAULT_ORDER
The default order for the LoggingApplicationListener.
|
static java.lang.String |
LOG_FILE_BEAN_NAME
The name of the
LogFile bean. |
static java.lang.String |
LOGGER_GROUPS_BEAN_NAME
The name of the
LoggerGroups bean. |
static java.lang.String |
LOGGING_SYSTEM_BEAN_NAME
The name of the
LoggingSystem bean. |
static java.lang.String |
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.
|
| Constructor and Description |
|---|
LoggingApplicationListener() |
| Modifier and Type | Method and Description |
|---|---|
int |
getOrder() |
protected void |
initialize(org.springframework.core.env.ConfigurableEnvironment environment,
java.lang.ClassLoader classLoader)
Initialize the logging system according to preferences expressed through the
Environment and the classpath. |
protected void |
initializeSpringBootLogging(LoggingSystem system,
LogLevel springBootLogging)
Initialize loggers based on the
springBootLogging setting. |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent event) |
protected void |
setLogLevels(LoggingSystem system,
org.springframework.core.env.ConfigurableEnvironment environment)
Set logging levels based on relevant
Environment properties. |
void |
setOrder(int order) |
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).
|
void |
setSpringBootLogging(LogLevel springBootLogging)
Sets a custom logging level to be used for Spring Boot and related libraries.
|
boolean |
supportsEventType(org.springframework.core.ResolvableType resolvableType) |
boolean |
supportsSourceType(java.lang.Class<?> sourceType) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsupportsEventTypepublic static final int DEFAULT_ORDER
public static final java.lang.String CONFIG_PROPERTY
public static final java.lang.String REGISTER_SHUTDOWN_HOOK_PROPERTY
public static final java.lang.String LOGGING_SYSTEM_BEAN_NAME
LoggingSystem bean.public static final java.lang.String LOG_FILE_BEAN_NAME
LogFile bean.public static final java.lang.String LOGGER_GROUPS_BEAN_NAME
LoggerGroups bean.public boolean supportsEventType(org.springframework.core.ResolvableType resolvableType)
supportsEventType in interface org.springframework.context.event.GenericApplicationListenerpublic boolean supportsSourceType(java.lang.Class<?> sourceType)
supportsSourceType in interface org.springframework.context.event.SmartApplicationListenerpublic void onApplicationEvent(org.springframework.context.ApplicationEvent event)
onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>protected void initialize(org.springframework.core.env.ConfigurableEnvironment environment,
java.lang.ClassLoader classLoader)
Environment and the classpath.environment - the environmentclassLoader - the classloaderprotected void initializeSpringBootLogging(LoggingSystem system, LogLevel springBootLogging)
springBootLogging setting. By default this implementation will pick an appropriate
set of loggers to configure based on the level.system - the logging systemspringBootLogging - the spring boot logging level requestedprotected void setLogLevels(LoggingSystem system, org.springframework.core.env.ConfigurableEnvironment environment)
Environment properties.system - the logging systemenvironment - the environmentpublic void setOrder(int order)
public int getOrder()
getOrder in interface org.springframework.context.event.SmartApplicationListenergetOrder in interface org.springframework.core.Orderedpublic void setSpringBootLogging(LogLevel springBootLogging)
springBootLogging - the logging levelpublic void setParseArgs(boolean parseArgs)
true.parseArgs - if arguments should be parsed