Log classpath once environment has been prepared

Previously, the classpath would be logged in response to the
ApplicationStartedEvent. At this point, logging could be disabled
while the logging system is being initialized, or because the
log levels configured in the environment have not yet been applied.

This commit moves the logging to happen in response to an
ApplicationEnvironmentPreparedEvent by which point the logging
system has been initialized and its levels have been configured.

Closes gh-5313
This commit is contained in:
Andy Wilkinson 2016-04-19 16:20:35 +01:00
parent 601791c664
commit e69ec6bb09
1 changed files with 7 additions and 6 deletions

View File

@ -22,17 +22,18 @@ import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.GenericApplicationListener;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.core.ResolvableType;
/**
* A {@link SmartApplicationListener} that reacts to {@link ApplicationStartedEvent start
* events} and to {@link ApplicationFailedEvent failed events} by logging the classpath of
* the thread context class loader (TCCL) at {@code DEBUG} level.
* A {@link SmartApplicationListener} that reacts to
* {@link ApplicationEnvironmentPreparedEvent environment prepared events} and to
* {@link ApplicationFailedEvent failed events} by logging the classpath of the thread
* context class loader (TCCL) at {@code DEBUG} level.
*
* @author Andy Wilkinson
*/
@ -46,7 +47,7 @@ public final class ClasspathLoggingApplicationListener
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (this.logger.isDebugEnabled()) {
if (event instanceof ApplicationStartedEvent) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
this.logger
.debug("Application started with classpath: " + getClasspath());
}
@ -68,7 +69,7 @@ public final class ClasspathLoggingApplicationListener
if (type == null) {
return false;
}
return ApplicationStartedEvent.class.isAssignableFrom(type)
return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(type)
|| ApplicationFailedEvent.class.isAssignableFrom(type);
}