Register Logback StatusListener when using custom Logback file

Update `LogbackLoggingSystem` so that the `OnErrorConsoleStatusListener`
is also registered when loading a custom Logback configuration file.

See gh-43931

Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
This commit is contained in:
Dmytro Nosan
2025-01-22 16:26:53 +02:00
committed by Phillip Webb
parent b9f3d522cf
commit 258eb29978
6 changed files with 75 additions and 22 deletions

View File

@@ -10,3 +10,7 @@ logging.structured.format.console=smoketest.structuredlogging.CustomStructuredLo
#---
spring.config.activate.on-profile=on-error
logging.structured.json.customizer=smoketest.structuredlogging.DuplicateJsonMembersCustomizer
#---
logging.config=classpath:custom-logback.xml
spring.config.activate.on-profile=on-error-custom-logback-file
logging.structured.json.customizer=smoketest.structuredlogging.DuplicateJsonMembersCustomizer

View File

@@ -0,0 +1,11 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="org.springframework.boot.logging.logback.StructuredLogEncoder">
<format>ecs</format>
<charset>UTF-8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

View File

@@ -71,4 +71,11 @@ class SampleStructuredLoggingApplicationTests {
assertThat(output).contains("The name 'test' has already been written");
}
@Test
void shouldCaptureCustomizerErrorWhenUsingCustomLogbackFile(CapturedOutput output) {
SampleStructuredLoggingApplication
.main(new String[] { "--spring.profiles.active=on-error-custom-logback-file" });
assertThat(output).contains("The name 'test' has already been written");
}
}