From e69ec6bb09e93aa5d240cfdb826e93cebb91278e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 19 Apr 2016 16:20:35 +0100 Subject: [PATCH] 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 --- .../ClasspathLoggingApplicationListener.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java index 9b70b54d323..3dcd654818f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java @@ -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); }