From d4d6a43fc2c42186fd3283a41743b2b7702be08c Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 1 Dec 2017 15:27:55 +0900 Subject: [PATCH 1/2] Fix system properties in file-appender.xml See gh-11232 --- .../springframework/boot/logging/logback/file-appender.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/file-appender.xml b/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/file-appender.xml index 383e02750a0..deae1a96a66 100644 --- a/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/file-appender.xml +++ b/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/file-appender.xml @@ -14,8 +14,8 @@ initialization performed by Boot ${LOG_FILE} ${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz - ${MAX_FILE_SIZE:-10MB} - ${MAX_HISTORY:-0} + ${LOG_FILE_MAX_SIZE:-10MB} + ${LOG_FILE_MAX_HISTORY:-0} From 953d69ce0b861688214f30c37d8c9ae04a5e5ebe Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 6 Dec 2017 15:30:32 +0000 Subject: [PATCH 2/2] Polish "Fix system properties in file-appender.xml" Closes gh-11232 --- .../logback/LogbackLoggingSystemTests.java | 31 +++++++++++++++++++ .../test/resources/logback-include-base.xml | 4 +++ 2 files changed, 35 insertions(+) create mode 100644 spring-boot-project/spring-boot/src/test/resources/logback-include-base.xml diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index e462af5649d..14cae94634c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -362,6 +362,22 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { .toString()).isEqualTo("100 MB"); } + @Test + public void testMaxFileSizePropertyWithXmlConfiguration() throws Exception { + MockEnvironment environment = new MockEnvironment(); + environment.setProperty("logging.file.max-size", "100MB"); + LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext( + environment); + File file = new File(tmpDir(), "logback-test.log"); + LogFile logFile = getLogFile(file.getPath(), null); + this.loggingSystem.initialize(loggingInitializationContext, + "classpath:logback-include-base.xml", logFile); + this.logger.info("Hello world"); + assertThat(getLineWithText(file, "Hello world")).contains("INFO"); + assertThat(ReflectionTestUtils.getField(getRollingPolicy(), "maxFileSize") + .toString()).isEqualTo("100 MB"); + } + @Test public void testMaxHistoryProperty() throws Exception { MockEnvironment environment = new MockEnvironment(); @@ -376,6 +392,21 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { assertThat(getRollingPolicy().getMaxHistory()).isEqualTo(30); } + @Test + public void testMaxHistoryPropertyWithXmlConfiguration() throws Exception { + MockEnvironment environment = new MockEnvironment(); + environment.setProperty("logging.file.max-history", "30"); + LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext( + environment); + File file = new File(tmpDir(), "logback-test.log"); + LogFile logFile = getLogFile(file.getPath(), null); + this.loggingSystem.initialize(loggingInitializationContext, + "classpath:logback-include-base.xml", logFile); + this.logger.info("Hello world"); + assertThat(getLineWithText(file, "Hello world")).contains("INFO"); + assertThat(getRollingPolicy().getMaxHistory()).isEqualTo(30); + } + @Test public void exceptionsIncludeClassPackaging() throws Exception { this.loggingSystem.beforeInitialize(); diff --git a/spring-boot-project/spring-boot/src/test/resources/logback-include-base.xml b/spring-boot-project/spring-boot/src/test/resources/logback-include-base.xml new file mode 100644 index 00000000000..b8a41480d7d --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/resources/logback-include-base.xml @@ -0,0 +1,4 @@ + + + +