Skip to content

Commit 3c00bf3

Browse files
Adapt to changes in Logback include processing
Fixes gh-40491
1 parent 86a3099 commit 3c00bf3

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringBootJoranConfigurator.java

+10
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public void addElementSelectorAndActionAssociations(RuleStore ruleStore) {
107107
ruleStore.addTransparentPathPart("springProfile");
108108
}
109109

110+
@Override
111+
public void buildModelInterpretationContext() {
112+
super.buildModelInterpretationContext();
113+
this.modelInterpretationContext.setConfiguratorSupplier(() -> {
114+
SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(this.initializationContext);
115+
configurator.setContext(this.context);
116+
return configurator;
117+
});
118+
}
119+
110120
boolean configureUsingAotGeneratedArtifacts() {
111121
if (!new PatternRules(getContext()).load()) {
112122
return false;

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

+15
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ void profileActive() throws Exception {
8383
assertThat(this.output).contains("Hello");
8484
}
8585

86+
@Test
87+
void profileInIncludeActive() throws Exception {
88+
this.environment.setActiveProfiles("production");
89+
initialize("profile-in-include.xml");
90+
this.logger.trace("Hello");
91+
assertThat(this.output).contains("Hello");
92+
}
93+
8694
@Test
8795
void multipleNamesFirstProfileActive() throws Exception {
8896
this.environment.setActiveProfiles("production");
@@ -203,6 +211,13 @@ void springPropertyInIfWhenFalse() throws Exception {
203211
assertThat(this.context.getProperty("MYCHECK")).isNull();
204212
}
205213

214+
@Test
215+
void springPropertyInInclude() throws Exception {
216+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.example-property=test");
217+
initialize("property-in-include.xml");
218+
assertThat(this.context.getProperty("MINE")).isEqualTo("test");
219+
}
220+
206221
@Test
207222
void addsAotContributionToContextDuringAotProcessing() throws Exception {
208223
withSystemProperty("spring.aot.processing", "true", () -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<included>
2+
<springProfile name="production">
3+
<logger name="org.springframework.boot.logging.logback" level="TRACE" />
4+
</springProfile>
5+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<included>
2+
<springProperty scope="context" name="MINE" source="my.example-property" defaultValue="default-test" />
3+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/base.xml" />
4+
<include resource="org/springframework/boot/logging/logback/include-with-profile.xml" />
5+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/base.xml" />
4+
<include resource="org/springframework/boot/logging/logback/include-with-property.xml" />
5+
</configuration>

0 commit comments

Comments
 (0)