Commit 35994b06 authored by Phillip Webb's avatar Phillip Webb

Polish 'Remove ResourceUtils.getURL logging config check'

Extend `initializeSystem` to search the exception stack for a
FileNotFoundException before reporting the error. This allows
us to provide a similar stack trace to the one that used to be
thrown when we had the `ResourceUtils.getURL` check.

See gh-22946
parent 684b65e8
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.boot.context.logging; package org.springframework.boot.context.logging;
import java.io.FileNotFoundException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -316,9 +317,14 @@ public class LoggingApplicationListener implements GenericApplicationListener { ...@@ -316,9 +317,14 @@ public class LoggingApplicationListener implements GenericApplicationListener {
system.initialize(initializationContext, logConfig, logFile); system.initialize(initializationContext, logConfig, logFile);
} }
catch (Exception ex) { catch (Exception ex) {
Throwable exceptionToReport = ex;
while (exceptionToReport != null && !(exceptionToReport instanceof FileNotFoundException)) {
exceptionToReport = exceptionToReport.getCause();
}
exceptionToReport = (exceptionToReport != null) ? exceptionToReport : ex;
// NOTE: We can't use the logger here to report the problem // NOTE: We can't use the logger here to report the problem
System.err.println("Logging system failed to initialize using configuration from '" + logConfig + "'"); System.err.println("Logging system failed to initialize using configuration from '" + logConfig + "'");
ex.printStackTrace(System.err); exceptionToReport.printStackTrace(System.err);
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
} }
} }
......
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -165,9 +165,10 @@ class LoggingApplicationListenerTests { ...@@ -165,9 +165,10 @@ class LoggingApplicationListenerTests {
addPropertiesToEnvironment(this.context, "logging.config=doesnotexist.xml"); addPropertiesToEnvironment(this.context, "logging.config=doesnotexist.xml");
assertThatIllegalStateException().isThrownBy(() -> { assertThatIllegalStateException().isThrownBy(() -> {
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
assertThat(this.output)
.contains("Logging system failed to initialize using configuration from 'doesnotexist.xml'");
}); });
assertThat(this.output)
.contains("Logging system failed to initialize using configuration from 'doesnotexist.xml'")
.doesNotContain("JoranException");
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment