Merge pull request #11232 from Johnny Lim

* gh-11232:
  Polish "Fix system properties in file-appender.xml"
  Fix system properties in file-appender.xml
This commit is contained in:
Andy Wilkinson 2017-12-06 15:31:32 +00:00
commit 6d6abce55c
3 changed files with 37 additions and 2 deletions

View File

@ -14,8 +14,8 @@ initialization performed by Boot
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>${MAX_FILE_SIZE:-10MB}</maxFileSize>
<maxHistory>${MAX_HISTORY:-0}</maxHistory>
<maxFileSize>${LOG_FILE_MAX_SIZE:-10MB}</maxFileSize>
<maxHistory>${LOG_FILE_MAX_HISTORY:-0}</maxHistory>
</rollingPolicy>
</appender>
</included>

View File

@ -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();

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
</configuration>