Skip to content

Commit d4fe3bf

Browse files
committed
Merge branch '3.1.x'
Closes gh-37446
2 parents 77f0828 + af244e1 commit d4fe3bf

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) {
104104
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
105105
ThresholdFilter filter = new ThresholdFilter();
106106
filter.setLevel(resolve(config, "${CONSOLE_LOG_THRESHOLD}"));
107+
filter.start();
107108
appender.addFilter(filter);
108109
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
109110
encoder.setPattern(resolve(config, "${CONSOLE_LOG_PATTERN}"));
@@ -118,6 +119,7 @@ private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config, String
118119
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
119120
ThresholdFilter filter = new ThresholdFilter();
120121
filter.setLevel(resolve(config, "${FILE_LOG_THRESHOLD}"));
122+
filter.start();
121123
appender.addFilter(filter);
122124
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
123125
encoder.setPattern(resolve(config, "${FILE_LOG_PATTERN}"));

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.lang.reflect.Modifier;
2222
import java.nio.charset.Charset;
2323
import java.nio.charset.StandardCharsets;
24+
import java.nio.file.Path;
2425
import java.util.Arrays;
2526
import java.util.EnumSet;
2627
import java.util.HashSet;
@@ -90,6 +91,7 @@
9091
* @author Eddú Meléndez
9192
* @author Scott Frederick
9293
* @author Jonatan Ivanov
94+
* @author Moritz Halbritter
9395
*/
9496
@ExtendWith(OutputCaptureExtension.class)
9597
class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
@@ -801,6 +803,29 @@ void whenConfigLocationIsXmlAndHasQueryParametersThenIllegalArgumentExceptionSho
801803
.satisfies((ex) -> assertThat(ex.getCause()).isNotInstanceOf(IllegalArgumentException.class));
802804
}
803805

806+
@Test
807+
void shouldRespectConsoleThreshold(CapturedOutput output) {
808+
this.environment.setProperty("logging.threshold.console", "warn");
809+
this.loggingSystem.beforeInitialize();
810+
initialize(this.initializationContext, null, null);
811+
this.logger.info("Some info message");
812+
this.logger.warn("Some warn message");
813+
assertThat(output).doesNotContain("Some info message").contains("Some warn message");
814+
}
815+
816+
@Test
817+
void shouldRespectFileThreshold() {
818+
this.environment.setProperty("logging.threshold.file", "warn");
819+
this.loggingSystem.beforeInitialize();
820+
initialize(this.initializationContext, null, getLogFile(null, tmpDir()));
821+
this.logger.info("Some info message");
822+
this.logger.warn("Some warn message");
823+
Path file = Path.of(tmpDir(), "spring.log");
824+
assertThat(file).content(StandardCharsets.UTF_8)
825+
.doesNotContain("Some info message")
826+
.contains("Some warn message");
827+
}
828+
804829
private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
805830
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
806831
this.loggingSystem.beforeInitialize();

0 commit comments

Comments
 (0)