Skip to content

Commit 61e427c

Browse files
committed
Merge branch '3.5.x'
Closes gh-48516
2 parents b881f92 + 559106f commit 61e427c

File tree

8 files changed

+157
-0
lines changed

8 files changed

+157
-0
lines changed

config/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<suppress files="SpringBootJoranConfiguratorTests\.java" checks="IllegalImport" />
4747
<suppress files="LogbackMetricsAutoConfiguration\.java" checks="IllegalImport" />
4848
<suppress files="RemoteUrlPropertyExtractorTests\.java" checks="IllegalImport" />
49+
<suppress files="SampleLog4j2Application\.java" checks="IllegalImport" />
4950
<suppress files="SampleLogbackApplication\.java" checks="IllegalImport" />
5051
<suppress files="OutputCaptureRuleTests" checks="SpringJUnit5" />
5152
<suppress files="[\\/]smoke-test[\\/]" checks="SpringJavadoc" message="\@since" />

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ include ":smoke-test:spring-boot-smoke-test-jetty-jsp"
425425
include ":smoke-test:spring-boot-smoke-test-jetty-ssl"
426426
include ":smoke-test:spring-boot-smoke-test-kafka"
427427
include ":smoke-test:spring-boot-smoke-test-liquibase"
428+
include ":smoke-test:spring-boot-smoke-test-log4j2"
428429
include ":smoke-test:spring-boot-smoke-test-logback"
429430
include ":smoke-test:spring-boot-smoke-test-oauth2-authorization-server"
430431
include ":smoke-test:spring-boot-smoke-test-oauth2-client"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "java"
19+
}
20+
21+
description = "Spring Boot Log4j2 smoke test"
22+
23+
dependencies {
24+
modules {
25+
module("org.springframework.boot:spring-boot-starter-logging") {
26+
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
27+
}
28+
}
29+
30+
implementation(project(":starter:spring-boot-starter"))
31+
implementation(project(":starter:spring-boot-starter-log4j2"))
32+
33+
testImplementation(project(":starter:spring-boot-starter-test"))
34+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.log4j2;
18+
19+
import jakarta.annotation.PostConstruct;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
import org.springframework.boot.SpringApplication;
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
26+
@SpringBootApplication
27+
public class SampleLog4j2Application {
28+
29+
private static final Logger logger = LoggerFactory.getLogger(SampleLog4j2Application.class);
30+
31+
@PostConstruct
32+
public void logSomething() {
33+
logger.debug("Sample Debug Message");
34+
logger.trace("Sample Trace Message");
35+
}
36+
37+
public static void main(String[] args) {
38+
SpringApplication.run(SampleLog4j2Application.class, args).close();
39+
}
40+
41+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@NullMarked
18+
package smoketest.log4j2;
19+
20+
import org.jspecify.annotations.NullMarked;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
logging.log4j2.config.override=classpath:org/springframework/boot/logging/log4j2/log4j2.xml
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<SpringProfile name="staging">
4+
<Loggers>
5+
<Logger name="smoketest.log4j2" level="TRACE"/>
6+
<Root level="INFO">
7+
<AppenderRef ref="Console"/>
8+
</Root>
9+
</Loggers>
10+
</SpringProfile>
11+
<Loggers>
12+
<Logger name="smoketest.log4j2" level="DEBUG"/>
13+
<Root level="INFO">
14+
<AppenderRef ref="Console"/>
15+
</Root>
16+
</Loggers>
17+
</Configuration>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.log4j2;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.extension.ExtendWith;
21+
22+
import org.springframework.boot.test.system.CapturedOutput;
23+
import org.springframework.boot.test.system.OutputCaptureExtension;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
@ExtendWith(OutputCaptureExtension.class)
28+
class SampleLog4j2ApplicationTests {
29+
30+
@Test
31+
void testLoadedCustomLogbackConfig(CapturedOutput output) {
32+
SampleLog4j2Application.main(new String[0]);
33+
assertThat(output).contains("Sample Debug Message").doesNotContain("Sample Trace Message");
34+
}
35+
36+
@Test
37+
void testProfile(CapturedOutput output) {
38+
SampleLog4j2Application.main(new String[] { "--spring.profiles.active=staging" });
39+
assertThat(output).contains("Sample Debug Message").contains("Sample Trace Message");
40+
}
41+
42+
}

0 commit comments

Comments
 (0)