Browse Source

Merge branch '3.5.x'

Closes gh-48516
pull/48523/head
Stéphane Nicoll 5 days ago
parent
commit
61e427c101
  1. 1
      config/checkstyle/checkstyle-suppressions.xml
  2. 1
      settings.gradle
  3. 34
      smoke-test/spring-boot-smoke-test-log4j2/build.gradle
  4. 41
      smoke-test/spring-boot-smoke-test-log4j2/src/main/java/smoketest/log4j2/SampleLog4j2Application.java
  5. 20
      smoke-test/spring-boot-smoke-test-log4j2/src/main/java/smoketest/log4j2/package-info.java
  6. 1
      smoke-test/spring-boot-smoke-test-log4j2/src/main/resources/application.properties
  7. 17
      smoke-test/spring-boot-smoke-test-log4j2/src/main/resources/log4j2-spring.xml
  8. 42
      smoke-test/spring-boot-smoke-test-log4j2/src/test/java/smoketest/log4j2/SampleLog4j2ApplicationTests.java

1
config/checkstyle/checkstyle-suppressions.xml

@ -46,6 +46,7 @@ @@ -46,6 +46,7 @@
<suppress files="SpringBootJoranConfiguratorTests\.java" checks="IllegalImport" />
<suppress files="LogbackMetricsAutoConfiguration\.java" checks="IllegalImport" />
<suppress files="RemoteUrlPropertyExtractorTests\.java" checks="IllegalImport" />
<suppress files="SampleLog4j2Application\.java" checks="IllegalImport" />
<suppress files="SampleLogbackApplication\.java" checks="IllegalImport" />
<suppress files="OutputCaptureRuleTests" checks="SpringJUnit5" />
<suppress files="[\\/]smoke-test[\\/]" checks="SpringJavadoc" message="\@since" />

1
settings.gradle

@ -425,6 +425,7 @@ include ":smoke-test:spring-boot-smoke-test-jetty-jsp" @@ -425,6 +425,7 @@ include ":smoke-test:spring-boot-smoke-test-jetty-jsp"
include ":smoke-test:spring-boot-smoke-test-jetty-ssl"
include ":smoke-test:spring-boot-smoke-test-kafka"
include ":smoke-test:spring-boot-smoke-test-liquibase"
include ":smoke-test:spring-boot-smoke-test-log4j2"
include ":smoke-test:spring-boot-smoke-test-logback"
include ":smoke-test:spring-boot-smoke-test-oauth2-authorization-server"
include ":smoke-test:spring-boot-smoke-test-oauth2-client"

34
smoke-test/spring-boot-smoke-test-log4j2/build.gradle

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "java"
}
description = "Spring Boot Log4j2 smoke test"
dependencies {
modules {
module("org.springframework.boot:spring-boot-starter-logging") {
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
}
}
implementation(project(":starter:spring-boot-starter"))
implementation(project(":starter:spring-boot-starter-log4j2"))
testImplementation(project(":starter:spring-boot-starter-test"))
}

41
smoke-test/spring-boot-smoke-test-log4j2/src/main/java/smoketest/log4j2/SampleLog4j2Application.java

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package smoketest.log4j2;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SampleLog4j2Application {
private static final Logger logger = LoggerFactory.getLogger(SampleLog4j2Application.class);
@PostConstruct
public void logSomething() {
logger.debug("Sample Debug Message");
logger.trace("Sample Trace Message");
}
public static void main(String[] args) {
SpringApplication.run(SampleLog4j2Application.class, args).close();
}
}

20
smoke-test/spring-boot-smoke-test-log4j2/src/main/java/smoketest/log4j2/package-info.java

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.log4j2;
import org.jspecify.annotations.NullMarked;

1
smoke-test/spring-boot-smoke-test-log4j2/src/main/resources/application.properties

@ -0,0 +1 @@ @@ -0,0 +1 @@
logging.log4j2.config.override=classpath:org/springframework/boot/logging/log4j2/log4j2.xml

17
smoke-test/spring-boot-smoke-test-log4j2/src/main/resources/log4j2-spring.xml

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<SpringProfile name="staging">
<Loggers>
<Logger name="smoketest.log4j2" level="TRACE"/>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</SpringProfile>
<Loggers>
<Logger name="smoketest.log4j2" level="DEBUG"/>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

42
smoke-test/spring-boot-smoke-test-log4j2/src/test/java/smoketest/log4j2/SampleLog4j2ApplicationTests.java

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package smoketest.log4j2;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(OutputCaptureExtension.class)
class SampleLog4j2ApplicationTests {
@Test
void testLoadedCustomLogbackConfig(CapturedOutput output) {
SampleLog4j2Application.main(new String[0]);
assertThat(output).contains("Sample Debug Message").doesNotContain("Sample Trace Message");
}
@Test
void testProfile(CapturedOutput output) {
SampleLog4j2Application.main(new String[] { "--spring.profiles.active=staging" });
assertThat(output).contains("Sample Debug Message").contains("Sample Trace Message");
}
}
Loading…
Cancel
Save