Skip to content

Commit 1b62aba

Browse files
committed
Configure context on SizeAndTimeBasedRollingPolicy
Previously, when file-based logging was enabled, Logback would output the following during logging system initialization: LOGBACK: No context given for c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy This commit updates the default logback configuration to set the context on the SizeAndTimeBasedRollingPolicy that it creates. Fixes gh-21056
1 parent 73a1047 commit 1b62aba

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -139,6 +139,7 @@ private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config, String
139139
private void setRollingPolicy(RollingFileAppender<ILoggingEvent> appender, LogbackConfigurator config,
140140
String logFile) {
141141
SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new SizeAndTimeBasedRollingPolicy<>();
142+
rollingPolicy.setContext(config.getContext());
142143
rollingPolicy.setCleanHistoryOnStart(
143144
this.patterns.getProperty("logging.file.clean-history-on-start", Boolean.class, false));
144145
rollingPolicy.setFileNamePattern(

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,6 +111,7 @@ void withFile(CapturedOutput output) {
111111
this.loggingSystem.initialize(this.initializationContext, null, getLogFile(null, tmpDir()));
112112
this.logger.info("Hello world");
113113
File file = new File(tmpDir() + "/spring.log");
114+
assertThat(output).doesNotContain("LOGBACK:");
114115
assertThat(output).contains("Hello world").doesNotContain("Hidden");
115116
assertThat(getLineWithText(output, "Hello world")).contains("INFO");
116117
assertThat(file.exists()).isTrue();

0 commit comments

Comments
 (0)