Skip to content

Commit 35994b0

Browse files
committed
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
1 parent 684b65e commit 35994b0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.context.logging;
1818

19+
import java.io.FileNotFoundException;
1920
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.Map;
@@ -316,9 +317,14 @@ private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem
316317
system.initialize(initializationContext, logConfig, logFile);
317318
}
318319
catch (Exception ex) {
320+
Throwable exceptionToReport = ex;
321+
while (exceptionToReport != null && !(exceptionToReport instanceof FileNotFoundException)) {
322+
exceptionToReport = exceptionToReport.getCause();
323+
}
324+
exceptionToReport = (exceptionToReport != null) ? exceptionToReport : ex;
319325
// NOTE: We can't use the logger here to report the problem
320326
System.err.println("Logging system failed to initialize using configuration from '" + logConfig + "'");
321-
ex.printStackTrace(System.err);
327+
exceptionToReport.printStackTrace(System.err);
322328
throw new IllegalStateException(ex);
323329
}
324330
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -165,9 +165,10 @@ void overrideConfigDoesNotExist() {
165165
addPropertiesToEnvironment(this.context, "logging.config=doesnotexist.xml");
166166
assertThatIllegalStateException().isThrownBy(() -> {
167167
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
168-
assertThat(this.output)
169-
.contains("Logging system failed to initialize using configuration from 'doesnotexist.xml'");
170168
});
169+
assertThat(this.output)
170+
.contains("Logging system failed to initialize using configuration from 'doesnotexist.xml'")
171+
.doesNotContain("JoranException");
171172
}
172173

173174
@Test

0 commit comments

Comments
 (0)