Adapt to changes in Logback include processing

Fixes gh-40491
This commit is contained in:
Scott Frederick 2024-04-26 13:33:51 -05:00
parent 86a3099782
commit 3c00bf367d
6 changed files with 43 additions and 0 deletions

View File

@ -107,6 +107,16 @@ class SpringBootJoranConfigurator extends JoranConfigurator {
ruleStore.addTransparentPathPart("springProfile");
}
@Override
public void buildModelInterpretationContext() {
super.buildModelInterpretationContext();
this.modelInterpretationContext.setConfiguratorSupplier(() -> {
SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(this.initializationContext);
configurator.setContext(this.context);
return configurator;
});
}
boolean configureUsingAotGeneratedArtifacts() {
if (!new PatternRules(getContext()).load()) {
return false;

View File

@ -83,6 +83,14 @@ class SpringBootJoranConfiguratorTests {
assertThat(this.output).contains("Hello");
}
@Test
void profileInIncludeActive() throws Exception {
this.environment.setActiveProfiles("production");
initialize("profile-in-include.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}
@Test
void multipleNamesFirstProfileActive() throws Exception {
this.environment.setActiveProfiles("production");
@ -203,6 +211,13 @@ class SpringBootJoranConfiguratorTests {
assertThat(this.context.getProperty("MYCHECK")).isNull();
}
@Test
void springPropertyInInclude() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.example-property=test");
initialize("property-in-include.xml");
assertThat(this.context.getProperty("MINE")).isEqualTo("test");
}
@Test
void addsAotContributionToContextDuringAotProcessing() throws Exception {
withSystemProperty("spring.aot.processing", "true", () -> {

View File

@ -0,0 +1,5 @@
<included>
<springProfile name="production">
<logger name="org.springframework.boot.logging.logback" level="TRACE" />
</springProfile>
</included>

View File

@ -0,0 +1,3 @@
<included>
<springProperty scope="context" name="MINE" source="my.example-property" defaultValue="default-test" />
</included>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<include resource="org/springframework/boot/logging/logback/include-with-profile.xml" />
</configuration>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<include resource="org/springframework/boot/logging/logback/include-with-property.xml" />
</configuration>