Skip to content

Commit aea45b5

Browse files
committed
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
1 parent db1c25a commit aea45b5

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Default logback configuration provided for import
55
-->
66

77
<included>
8-
<conversionRule conversionWord="applicationName" converterClass="org.springframework.boot.logging.logback.ApplicationNameConverter" />
9-
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
10-
<conversionRule conversionWord="correlationId" converterClass="org.springframework.boot.logging.logback.CorrelationIdConverter" />
11-
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
12-
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
8+
<conversionRule conversionWord="applicationName" class="org.springframework.boot.logging.logback.ApplicationNameConverter" />
9+
<conversionRule conversionWord="clr" class="org.springframework.boot.logging.logback.ColorConverter" />
10+
<conversionRule conversionWord="correlationId" class="org.springframework.boot.logging.logback.CorrelationIdConverter" />
11+
<conversionRule conversionWord="wex" class="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
12+
<conversionRule conversionWord="wEx" class="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
1313

1414
<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}}"/>
1515
<property name="CONSOLE_LOG_CHARSET" value="${CONSOLE_LOG_CHARSET:-${file.encoding:-UTF-8}}"/>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ void cleanUp() {
130130
((LoggerContext) LoggerFactory.getILoggerFactory()).stop();
131131
}
132132

133+
@Test
134+
void logbackDefaultsConfigurationDoesNotTriggerDeprecation(CapturedOutput output) {
135+
initialize(this.initializationContext, "classpath:logback-include-defaults.xml", null);
136+
this.logger.info("Hello world");
137+
assertThat(getLineWithText(output, "Hello world")).isEqualTo("[INFO] - Hello world");
138+
assertThat(output.toString()).doesNotContain("WARN").doesNotContain("deprecated");
139+
}
140+
141+
@Test
142+
void logbackBaseConfigurationDoesNotTriggerDeprecation(CapturedOutput output) {
143+
initialize(this.initializationContext, "classpath:logback-include-base.xml", null);
144+
this.logger.info("Hello world");
145+
assertThat(getLineWithText(output, "Hello world")).contains(" INFO ").endsWith(": Hello world");
146+
assertThat(output.toString()).doesNotContain("WARN").doesNotContain("deprecated");
147+
}
148+
133149
@Test
134150
@ClassPathOverrides({ "org.jboss.logging:jboss-logging:3.5.0.Final", "org.apache.logging.log4j:log4j-core:2.19.0" })
135151
void jbossLoggingRoutesThroughLog4j2ByDefault() {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
4+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder>
6+
<pattern>[%p] - %m%n</pattern>
7+
</encoder>
8+
</appender>
9+
<root level="INFO">
10+
<appender-ref ref="CONSOLE" />
11+
</root>
12+
</configuration>

0 commit comments

Comments
 (0)