8 changed files with 157 additions and 0 deletions
@ -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")) |
||||
} |
||||
@ -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(); |
||||
} |
||||
|
||||
} |
||||
@ -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; |
||||
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
logging.log4j2.config.override=classpath:org/springframework/boot/logging/log4j2/log4j2.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> |
||||
@ -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…
Reference in new issue