Merge branch '3.2.x' into 3.3.x

Closes gh-42989
This commit is contained in:
Phillip Webb 2024-11-04 14:34:17 -08:00
commit 4a7c757945
5 changed files with 28 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 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.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 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.

View File

@ -291,15 +291,10 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF
private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext, private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext,
URL url) throws JoranException { URL url) throws JoranException {
if (url.getPath().endsWith(".xml")) {
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext); JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
configurator.setContext(loggerContext); configurator.setContext(loggerContext);
configurator.doConfigure(url); configurator.doConfigure(url);
} }
else {
throw new IllegalArgumentException("Unsupported file extension in '" + url + "'. Only .xml is supported");
}
}
private void stopAndReset(LoggerContext loggerContext) { private void stopAndReset(LoggerContext loggerContext) {
loggerContext.stop(); loggerContext.stop();

View File

@ -37,6 +37,7 @@ import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggerContextListener; import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.core.ConsoleAppender; import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.rolling.RollingFileAppender; import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy; import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
import ch.qos.logback.core.util.DynamicClassLoadingException; import ch.qos.logback.core.util.DynamicClassLoadingException;
@ -848,8 +849,17 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> initialize(this.initializationContext, "classpath:logback-invalid-format.txt", .isThrownBy(() -> initialize(this.initializationContext, "classpath:logback-invalid-format.txt",
getLogFile(tmpDir() + "/tmp.log", null))) getLogFile(tmpDir() + "/tmp.log", null)))
.satisfies((ex) -> assertThat(ex.getCause()).isInstanceOf(IllegalArgumentException.class) .satisfies((ex) -> assertThat(ex.getCause()).isInstanceOf(JoranException.class)
.hasMessageStartingWith("Unsupported file extension")); .hasMessageStartingWith("Problem parsing XML document. See previously reported errors"));
}
@Test
void whenConfigLocationIsXmlFileWithoutExtensionShouldWork(CapturedOutput output) {
this.loggingSystem.beforeInitialize();
initialize(this.initializationContext, "classpath:logback-without-extension",
getLogFile(tmpDir() + "/tmp.log", null));
this.logger.info("No extension and works!");
assertThat(output.toString()).contains("No extension and works!");
} }
@Test @Test

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>