From 1b62abab9a4768ae66ddb85bdde931786c455b96 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 18 Jun 2020 11:01:26 +0100 Subject: [PATCH] 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 --- .../boot/logging/logback/DefaultLogbackConfiguration.java | 3 ++- .../boot/logging/logback/LogbackLoggingSystemTests.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java index e10012f1e9..3d2ec34a21 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DefaultLogbackConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,6 +139,7 @@ class DefaultLogbackConfiguration { private void setRollingPolicy(RollingFileAppender appender, LogbackConfigurator config, String logFile) { SizeAndTimeBasedRollingPolicy rollingPolicy = new SizeAndTimeBasedRollingPolicy<>(); + rollingPolicy.setContext(config.getContext()); rollingPolicy.setCleanHistoryOnStart( this.patterns.getProperty("logging.file.clean-history-on-start", Boolean.class, false)); rollingPolicy.setFileNamePattern( 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 2fab7a2f00..2d2ee47818 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -111,6 +111,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { this.loggingSystem.initialize(this.initializationContext, null, getLogFile(null, tmpDir())); this.logger.info("Hello world"); File file = new File(tmpDir() + "/spring.log"); + assertThat(output).doesNotContain("LOGBACK:"); assertThat(output).contains("Hello world").doesNotContain("Hidden"); assertThat(getLineWithText(output, "Hello world")).contains("INFO"); assertThat(file.exists()).isTrue();