Change Logback's maxHistory property default to 7 days

Closes gh-15875
pull/16930/head
Stephane Nicoll 6 years ago
parent 06c9e99895
commit ffbc545a47

@ -61,6 +61,8 @@ class DefaultLogbackConfiguration {
private static final DataSize MAX_FILE_SIZE = DataSize.ofMegabytes(10);
private static final Integer MAX_FILE_HISTORY = 7;
private final PropertyResolver patterns;
private final LogFile logFile;
@ -148,7 +150,7 @@ class DefaultLogbackConfiguration {
setMaxFileSize(rollingPolicy,
getDataSize("logging.file.max-size", MAX_FILE_SIZE));
rollingPolicy.setMaxHistory(this.patterns.getProperty("logging.file.max-history",
Integer.class, CoreConstants.UNBOUND_HISTORY));
Integer.class, MAX_FILE_HISTORY));
DataSize totalSizeCap = getDataSize("logging.file.total-size-cap",
DataSize.ofBytes(CoreConstants.UNBOUNDED_TOTAL_SIZE_CAP));
rollingPolicy.setTotalSizeCap(new FileSize(totalSizeCap.toBytes()));

@ -107,7 +107,7 @@
"type": "java.lang.Integer",
"description": "Maximum of archive log files to keep. Only supported with the default logback setup.",
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
"defaultValue": 0
"defaultValue": 7
},
{
"name": "logging.file.total-size-cap",

@ -16,7 +16,7 @@ initialization performed by Boot
<cleanHistoryOnStart>${LOG_FILE_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart>
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>${LOG_FILE_MAX_SIZE:-10MB}</maxFileSize>
<maxHistory>${LOG_FILE_MAX_HISTORY:-0}</maxHistory>
<maxHistory>${LOG_FILE_MAX_HISTORY:-7}</maxHistory>
<totalSizeCap>${LOG_FILE_TOTAL_SIZE_CAP:-0}</totalSizeCap>
</rollingPolicy>
</appender>

@ -27,7 +27,6 @@ import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
import org.hamcrest.Matcher;
@ -134,8 +133,7 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
assertThat(getLineWithText(file, "Hello world")).contains("INFO");
assertThat(ReflectionTestUtils.getField(getRollingPolicy(), "maxFileSize")
.toString()).isEqualTo("10 MB");
assertThat(getRollingPolicy().getMaxHistory())
.isEqualTo(CoreConstants.UNBOUND_HISTORY);
assertThat(getRollingPolicy().getMaxHistory()).isEqualTo(7);
}
@Test

Loading…
Cancel
Save