Browse Source

Adapt to Logback deprecation

This commit also adds a test so that we can catch this problem hopefully
sooner in the future.

Closes gh-42006
pull/42056/head
Stéphane Nicoll 1 year ago
parent
commit
aea45b5013
  1. 10
      spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml
  2. 16
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java
  3. 12
      spring-boot-project/spring-boot/src/test/resources/logback-include-defaults.xml

10
spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml

@ -5,11 +5,11 @@ Default logback configuration provided for import @@ -5,11 +5,11 @@ Default logback configuration provided for import
-->
<included>
<conversionRule conversionWord="applicationName" converterClass="org.springframework.boot.logging.logback.ApplicationNameConverter" />
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="correlationId" converterClass="org.springframework.boot.logging.logback.CorrelationIdConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="applicationName" class="org.springframework.boot.logging.logback.ApplicationNameConverter" />
<conversionRule conversionWord="clr" class="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="correlationId" class="org.springframework.boot.logging.logback.CorrelationIdConverter" />
<conversionRule conversionWord="wex" class="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" class="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr(%applicationName[%15.15t]){faint} %clr(${LOG_CORRELATION_PATTERN:-}){faint}%clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<property name="CONSOLE_LOG_CHARSET" value="${CONSOLE_LOG_CHARSET:-${file.encoding:-UTF-8}}"/>

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

@ -130,6 +130,22 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { @@ -130,6 +130,22 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
((LoggerContext) LoggerFactory.getILoggerFactory()).stop();
}
@Test
void logbackDefaultsConfigurationDoesNotTriggerDeprecation(CapturedOutput output) {
initialize(this.initializationContext, "classpath:logback-include-defaults.xml", null);
this.logger.info("Hello world");
assertThat(getLineWithText(output, "Hello world")).isEqualTo("[INFO] - Hello world");
assertThat(output.toString()).doesNotContain("WARN").doesNotContain("deprecated");
}
@Test
void logbackBaseConfigurationDoesNotTriggerDeprecation(CapturedOutput output) {
initialize(this.initializationContext, "classpath:logback-include-base.xml", null);
this.logger.info("Hello world");
assertThat(getLineWithText(output, "Hello world")).contains(" INFO ").endsWith(": Hello world");
assertThat(output.toString()).doesNotContain("WARN").doesNotContain("deprecated");
}
@Test
@ClassPathOverrides({ "org.jboss.logging:jboss-logging:3.5.0.Final", "org.apache.logging.log4j:log4j-core:2.19.0" })
void jbossLoggingRoutesThroughLog4j2ByDefault() {

12
spring-boot-project/spring-boot/src/test/resources/logback-include-defaults.xml

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%p] - %m%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
Loading…
Cancel
Save