Skip to content

Commit c9cc1da

Browse files
quaffsnicoll
authored andcommitted
Detect logback config location as xml if path ends with .xml
See gh-37039
1 parent 5b68e5b commit c9cc1da

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private void reportConfigurationErrorsIfNecessary(LoggerContext loggerContext) {
273273

274274
private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext,
275275
URL url) throws JoranException {
276-
if (url.toString().endsWith(".xml")) {
276+
if (url.getPath().endsWith(".xml")) {
277277
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
278278
configurator.setContext(loggerContext);
279279
configurator.doConfigure(url);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,25 @@ void whenConfigurationErrorIsDetectedUnderlyingCausesAreIncludedAsSuppressedExce
687687
.hasAtLeastOneElementOfType(DynamicClassLoadingException.class));
688688
}
689689

690+
@Test
691+
void whenConfigLocationIsNotXmlThenIllegalArgumentExceptionShouldBeThrown() {
692+
this.loggingSystem.beforeInitialize();
693+
assertThatIllegalStateException()
694+
.isThrownBy(() -> initialize(this.initializationContext, "file:///logback-nonexistent.txt",
695+
getLogFile(tmpDir() + "/tmp.log", null)))
696+
.satisfies((ex) -> assertThat(ex.getCause()).isInstanceOf(IllegalArgumentException.class)
697+
.hasMessageStartingWith("Unsupported file extension"));
698+
}
699+
700+
@Test
701+
void whenConfigLocationIsXmlAndHasQueryParametersThenIllegalArgumentExceptionShouldNotBeThrown() {
702+
this.loggingSystem.beforeInitialize();
703+
assertThatIllegalStateException()
704+
.isThrownBy(() -> initialize(this.initializationContext, "file:///logback-nonexistent.xml?raw=true",
705+
getLogFile(tmpDir() + "/tmp.log", null)))
706+
.satisfies((ex) -> assertThat(ex.getCause()).isNotInstanceOf(IllegalArgumentException.class));
707+
}
708+
690709
private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
691710
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
692711
this.loggingSystem.initialize(context, configLocation, logFile);

0 commit comments

Comments
 (0)