diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2FileXmlTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2FileXmlTests.java index c2d2e53d23b..d0fed17a85a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2FileXmlTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2FileXmlTests.java @@ -36,13 +36,20 @@ import static org.assertj.core.api.Assertions.assertThat; */ class Log4j2FileXmlTests extends Log4j2XmlTests { + @TempDir + File temp; + + @Override @BeforeEach - void configureLogFile(@TempDir File temp) { - System.setProperty(LoggingSystemProperties.LOG_FILE, new File(temp, "test.log").getAbsolutePath()); + void prepareConfiguration() { + System.setProperty(LoggingSystemProperties.LOG_FILE, new File(this.temp, "test.log").getAbsolutePath()); + super.prepareConfiguration(); } + @Override @AfterEach - void clearLogFile() { + void stopConfiguration() { + super.stopConfiguration(); System.clearProperty(LoggingSystemProperties.LOG_FILE); } @@ -75,8 +82,8 @@ class Log4j2FileXmlTests extends Log4j2XmlTests { @Test void whenLogDateformatPatternIsSetThenFileAppenderUsesIt() { - withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "custom", - () -> assertThat(fileAppenderPattern()).contains("custom")); + withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "dd-MM-yyyy", + () -> assertThat(fileAppenderPattern()).contains("dd-MM-yyyy")); } @Override diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2XmlTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2XmlTests.java index ddbd7ec2fa1..28ee9da47fd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2XmlTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4j2XmlTests.java @@ -24,6 +24,8 @@ import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationSource; import org.apache.logging.log4j.core.layout.PatternLayout; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.logging.LoggingSystemProperties; @@ -37,6 +39,18 @@ import static org.assertj.core.api.Assertions.assertThat; */ class Log4j2XmlTests { + private Configuration configuration; + + @BeforeEach + void prepareConfiguration() { + this.configuration = initializeConfiguration(); + } + + @AfterEach + void stopConfiguration() { + this.configuration.stop(); + } + @Test void whenLogExceptionConversionWordIsNotConfiguredThenConsoleUsesDefault() { assertThat(consolePattern()).contains("%xwEx"); @@ -66,8 +80,8 @@ class Log4j2XmlTests { @Test void whenLogDateformatPatternIsSetThenConsoleUsesIt() { - withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "custom", - () -> assertThat(consolePattern()).contains("custom")); + withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "dd-MM-yyyy", + () -> assertThat(consolePattern()).contains("dd-MM-yyyy")); } protected void withSystemProperty(String name, String value, Runnable action) {