|
|
|
@ -141,7 +141,7 @@ public class LoggingApplicationListener implements SmartApplicationListener { |
|
|
|
return isAssignableFrom(sourceType, SOURCE_TYPES); |
|
|
|
return isAssignableFrom(sourceType, SOURCE_TYPES); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isAssignableFrom(Class<?> type, Class<?>[] supportedTypes) { |
|
|
|
private boolean isAssignableFrom(Class<?> type, Class<?>... supportedTypes) { |
|
|
|
for (Class<?> supportedType : supportedTypes) { |
|
|
|
for (Class<?> supportedType : supportedTypes) { |
|
|
|
if (supportedType.isAssignableFrom(type)) { |
|
|
|
if (supportedType.isAssignableFrom(type)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
@ -153,25 +153,32 @@ public class LoggingApplicationListener implements SmartApplicationListener { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
if (event instanceof ApplicationEnvironmentPreparedEvent) { |
|
|
|
if (event instanceof ApplicationEnvironmentPreparedEvent) { |
|
|
|
ApplicationEnvironmentPreparedEvent available = (ApplicationEnvironmentPreparedEvent) event; |
|
|
|
onApplicationEnvironmentPreparedEvent((ApplicationEnvironmentPreparedEvent) event); |
|
|
|
initialize(available.getEnvironment(), available.getSpringApplication() |
|
|
|
|
|
|
|
.getClassLoader()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if (event instanceof ApplicationStartedEvent) { |
|
|
|
else if (event instanceof ApplicationStartedEvent) { |
|
|
|
if (System.getProperty(PID_KEY) == null) { |
|
|
|
onApplicationStartedEvent((ApplicationStartedEvent) event); |
|
|
|
System.setProperty(PID_KEY, new ApplicationPid().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LoggingSystem loggingSystem = LoggingSystem.get(ClassUtils |
|
|
|
|
|
|
|
.getDefaultClassLoader()); |
|
|
|
|
|
|
|
loggingSystem.beforeInitialize(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else if (event instanceof ContextClosedEvent) { |
|
|
|
LoggingSystem loggingSystem = LoggingSystem.get(ClassUtils |
|
|
|
onContextClosedEvent((ContextClosedEvent) event); |
|
|
|
.getDefaultClassLoader()); |
|
|
|
|
|
|
|
loggingSystem.cleanUp(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onApplicationEnvironmentPreparedEvent( |
|
|
|
|
|
|
|
ApplicationEnvironmentPreparedEvent event) { |
|
|
|
|
|
|
|
initialize(event.getEnvironment(), event.getSpringApplication().getClassLoader()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onApplicationStartedEvent(ApplicationStartedEvent event) { |
|
|
|
|
|
|
|
if (System.getProperty(PID_KEY) == null) { |
|
|
|
|
|
|
|
System.setProperty(PID_KEY, new ApplicationPid().toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LoggingSystem.get(ClassUtils.getDefaultClassLoader()).beforeInitialize(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onContextClosedEvent(ContextClosedEvent event) { |
|
|
|
|
|
|
|
LoggingSystem.get(ClassUtils.getDefaultClassLoader()).cleanUp(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initialize the logging system according to preferences expressed through the |
|
|
|
* Initialize the logging system according to preferences expressed through the |
|
|
|
* {@link Environment} and the classpath. |
|
|
|
* {@link Environment} and the classpath. |
|
|
|
|