Commit 3587ecb0 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '2.3.x'

parents 5a3232d6 0963218b
...@@ -36,13 +36,20 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -36,13 +36,20 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
class Log4j2FileXmlTests extends Log4j2XmlTests { class Log4j2FileXmlTests extends Log4j2XmlTests {
@TempDir
File temp;
@Override
@BeforeEach @BeforeEach
void configureLogFile(@TempDir File temp) { void prepareConfiguration() {
System.setProperty(LoggingSystemProperties.LOG_FILE, new File(temp, "test.log").getAbsolutePath()); System.setProperty(LoggingSystemProperties.LOG_FILE, new File(this.temp, "test.log").getAbsolutePath());
super.prepareConfiguration();
} }
@Override
@AfterEach @AfterEach
void clearLogFile() { void stopConfiguration() {
super.stopConfiguration();
System.clearProperty(LoggingSystemProperties.LOG_FILE); System.clearProperty(LoggingSystemProperties.LOG_FILE);
} }
...@@ -75,8 +82,8 @@ class Log4j2FileXmlTests extends Log4j2XmlTests { ...@@ -75,8 +82,8 @@ class Log4j2FileXmlTests extends Log4j2XmlTests {
@Test @Test
void whenLogDateformatPatternIsSetThenFileAppenderUsesIt() { void whenLogDateformatPatternIsSetThenFileAppenderUsesIt() {
withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "custom", withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "dd-MM-yyyy",
() -> assertThat(fileAppenderPattern()).contains("custom")); () -> assertThat(fileAppenderPattern()).contains("dd-MM-yyyy"));
} }
@Override @Override
......
...@@ -24,6 +24,8 @@ import org.apache.logging.log4j.core.config.Configuration; ...@@ -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.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource; import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.layout.PatternLayout; 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.junit.jupiter.api.Test;
import org.springframework.boot.logging.LoggingSystemProperties; import org.springframework.boot.logging.LoggingSystemProperties;
...@@ -37,6 +39,18 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -37,6 +39,18 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
class Log4j2XmlTests { class Log4j2XmlTests {
private Configuration configuration;
@BeforeEach
void prepareConfiguration() {
this.configuration = initializeConfiguration();
}
@AfterEach
void stopConfiguration() {
this.configuration.stop();
}
@Test @Test
void whenLogExceptionConversionWordIsNotConfiguredThenConsoleUsesDefault() { void whenLogExceptionConversionWordIsNotConfiguredThenConsoleUsesDefault() {
assertThat(consolePattern()).contains("%xwEx"); assertThat(consolePattern()).contains("%xwEx");
...@@ -66,8 +80,8 @@ class Log4j2XmlTests { ...@@ -66,8 +80,8 @@ class Log4j2XmlTests {
@Test @Test
void whenLogDateformatPatternIsSetThenConsoleUsesIt() { void whenLogDateformatPatternIsSetThenConsoleUsesIt() {
withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "custom", withSystemProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, "dd-MM-yyyy",
() -> assertThat(consolePattern()).contains("custom")); () -> assertThat(consolePattern()).contains("dd-MM-yyyy"));
} }
protected void withSystemProperty(String name, String value, Runnable action) { protected void withSystemProperty(String name, String value, Runnable action) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment