Refine exception handling in logging listener

Refine the exception handling block to cover initialization exceptions
without a log file.

Closes gh-23802
pull/23886/head
Phillip Webb 4 years ago
parent c85cc33ca9
commit 70b7326b73

@ -305,15 +305,16 @@ public class LoggingApplicationListener implements GenericApplicationListener {
} }
private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) { private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) {
LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment);
String logConfig = StringUtils.trimWhitespace(environment.getProperty(CONFIG_PROPERTY)); String logConfig = StringUtils.trimWhitespace(environment.getProperty(CONFIG_PROPERTY));
try {
LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment);
if (ignoreLogConfig(logConfig)) { if (ignoreLogConfig(logConfig)) {
system.initialize(initializationContext, null, logFile); system.initialize(initializationContext, null, logFile);
} }
else { else {
try {
system.initialize(initializationContext, logConfig, logFile); system.initialize(initializationContext, logConfig, logFile);
} }
}
catch (Exception ex) { catch (Exception ex) {
Throwable exceptionToReport = ex; Throwable exceptionToReport = ex;
while (exceptionToReport != null && !(exceptionToReport instanceof FileNotFoundException)) { while (exceptionToReport != null && !(exceptionToReport instanceof FileNotFoundException)) {
@ -326,7 +327,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
} }
} }
}
private boolean ignoreLogConfig(String logConfig) { private boolean ignoreLogConfig(String logConfig) {
return !StringUtils.hasLength(logConfig) || logConfig.startsWith("-D"); return !StringUtils.hasLength(logConfig) || logConfig.startsWith("-D");

Loading…
Cancel
Save