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