Update logging listener to use normal stack trace ordering by default
Previously, LoggingApplicationListener used %rEx as the default exception conversion word. This would result in the nested causes being logging in reverse order, i.e. the most deeply nested cause would be logged first. This commit updates the default to be %wEx and adds a test to verify the default behaviour. Closes gh-4247
This commit is contained in:
parent
2dee3a9fe9
commit
8ed472d6f9
|
|
@ -58,7 +58,7 @@ content into your application; rather pick only the properties that you need.
|
|||
|
||||
# LOGGING
|
||||
logging.config= # location of config file (default classpath:logback.xml for logback)
|
||||
logging.exception-conversion-word=%rEx # conversion word used when logging exceptions
|
||||
logging.exception-conversion-word=%wEx # conversion word used when logging exceptions
|
||||
logging.file=myapp.log
|
||||
logging.level.*= # levels for loggers, e.g. "logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)
|
||||
logging.path=/var/log
|
||||
|
|
|
|||
|
|
@ -200,7 +200,8 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
}
|
||||
|
||||
private void onApplicationPreparedEvent(ApplicationPreparedEvent event) {
|
||||
ConfigurableListableBeanFactory beanFactory = event.getApplicationContext().getBeanFactory();
|
||||
ConfigurableListableBeanFactory beanFactory = event.getApplicationContext()
|
||||
.getBeanFactory();
|
||||
if (!beanFactory.containsBean(LOGGING_SYSTEM_BEAN_NAME)) {
|
||||
beanFactory.registerSingleton(LOGGING_SYSTEM_BEAN_NAME, this.loggingSystem);
|
||||
}
|
||||
|
|
@ -236,7 +237,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
private String getExceptionConversionWord(ConfigurableEnvironment environment) {
|
||||
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
|
||||
"logging.");
|
||||
return resolver.getProperty("exception-conversion-word", "%rEx");
|
||||
return resolver.getProperty("exception-conversion-word", "%wEx");
|
||||
}
|
||||
|
||||
private void initializeEarlyLoggingLevel(ConfigurableEnvironment environment) {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
"name": "logging.exception-conversion-word",
|
||||
"type": "java.lang.String",
|
||||
"description": "Conversion word used when logging exceptions.",
|
||||
"defaultValue": "%rEx",
|
||||
"defaultValue": "%wEx",
|
||||
"sourceType": "org.springframework.boot.logging.LoggingApplicationListener"
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -336,15 +336,27 @@ public class LoggingApplicationListenerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void overrideExceptionConversionWord() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"logging.exceptionConversionWord:%ex");
|
||||
public void defaultExceptionConversionWord() throws Exception {
|
||||
this.initializer.initialize(this.context.getEnvironment(),
|
||||
this.context.getClassLoader());
|
||||
this.outputCapture.expect(containsString("Hello world"));
|
||||
this.outputCapture.expect(not(containsString("???")));
|
||||
this.outputCapture.expect(not(containsString("[junit-")));
|
||||
this.logger.info("Hello world", new RuntimeException("Expected"));
|
||||
this.outputCapture.expect(
|
||||
not(containsString("Wrapped by: java.lang.RuntimeException: Wrapper")));
|
||||
this.logger.info("Hello world",
|
||||
new RuntimeException("Wrapper", new RuntimeException("Expected")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overrideExceptionConversionWord() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"logging.exceptionConversionWord:%rEx");
|
||||
this.initializer.initialize(this.context.getEnvironment(),
|
||||
this.context.getClassLoader());
|
||||
this.outputCapture.expect(containsString("Hello world"));
|
||||
this.outputCapture.expect(
|
||||
containsString("Wrapped by: java.lang.RuntimeException: Wrapper"));
|
||||
this.logger.info("Hello world",
|
||||
new RuntimeException("Wrapper", new RuntimeException("Expected")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue