public class LoggingApplicationListener extends Object implements SmartApplicationListener
ApplicationListener
that configures a logging framework depending on what it
finds on the classpath and in the Environment
. If the environment contains a
property logging.config
then that will be used to initialize the logging
system, otherwise a default location is used. The classpath is probed for log4j and
logback and if those are present they will be reconfigured, otherwise vanilla
java.util.logging
will be used.
The default config locations are classpath:log4j.properties
or
classpath:log4j.xml
for log4j; classpath:logback.xml
for
logback; and classpath:logging.properties
for
java.util.logging
. If the correct one of those files is not found then
some sensible defaults are adopted from files of the same name but in the package
containing LoggingApplicationListener
.
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 logging.file
if found in
the environmentLOG_PATH
is set to the value of logging.path
if found in
the environmentPID
is set to the value of the current process ID if it can be
determinedModifier and Type | Field and Description |
---|---|
static String |
PID_KEY |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
LoggingApplicationListener() |
Modifier and Type | Method and Description |
---|---|
int |
getOrder() |
protected void |
initialize(ConfigurableEnvironment environment,
ClassLoader classLoader)
Initialize the logging system according to preferences expressed through the
Environment and the classpath. |
protected void |
initializeLogLevel(LoggingSystem system,
LogLevel level) |
void |
onApplicationEvent(ApplicationEvent event) |
void |
setOrder(int order) |
void |
setParseArgs(boolean parseArgs)
Sets if initialization arguments should be parsed for --debug and
--trace options.
|
void |
setSpringBootLogging(LogLevel springBootLogging)
Sets a custom logging level to be used for Spring Boot and related libraries.
|
boolean |
supportsEventType(Class<? extends ApplicationEvent> eventType) |
boolean |
supportsSourceType(Class<?> sourceType) |
public static final String PID_KEY
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType)
supportsEventType
in interface SmartApplicationListener
public boolean supportsSourceType(Class<?> sourceType)
supportsSourceType
in interface SmartApplicationListener
public void onApplicationEvent(ApplicationEvent event)
onApplicationEvent
in interface ApplicationListener<ApplicationEvent>
protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader)
Environment
and the classpath.protected void initializeLogLevel(LoggingSystem system, LogLevel level)
public void setOrder(int order)
public void setSpringBootLogging(LogLevel springBootLogging)
springBootLogging
- the logging levelpublic void setParseArgs(boolean parseArgs)
true
.parseArgs
- if arguments should be parsedCopyright © 2014 Pivotal Software, Inc.. All rights reserved.