commit
4a7c757945
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -291,14 +291,9 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF
|
|||
|
||||
private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext,
|
||||
URL url) throws JoranException {
|
||||
if (url.getPath().endsWith(".xml")) {
|
||||
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
|
||||
configurator.setContext(loggerContext);
|
||||
configurator.doConfigure(url);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported file extension in '" + url + "'. Only .xml is supported");
|
||||
}
|
||||
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
|
||||
configurator.setContext(loggerContext);
|
||||
configurator.doConfigure(url);
|
||||
}
|
||||
|
||||
private void stopAndReset(LoggerContext loggerContext) {
|
||||
|
|
|
@ -37,6 +37,7 @@ import ch.qos.logback.classic.LoggerContext;
|
|||
import ch.qos.logback.classic.spi.LoggerContextListener;
|
||||
import ch.qos.logback.core.ConsoleAppender;
|
||||
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.SizeAndTimeBasedRollingPolicy;
|
||||
import ch.qos.logback.core.util.DynamicClassLoadingException;
|
||||
|
@ -848,8 +849,17 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> initialize(this.initializationContext, "classpath:logback-invalid-format.txt",
|
||||
getLogFile(tmpDir() + "/tmp.log", null)))
|
||||
.satisfies((ex) -> assertThat(ex.getCause()).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageStartingWith("Unsupported file extension"));
|
||||
.satisfies((ex) -> assertThat(ex.getCause()).isInstanceOf(JoranException.class)
|
||||
.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
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue