From 68fc2329c8af655e06d7d0c0cc023fda4aced676 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Thu, 14 Jan 2021 16:13:30 -0800 Subject: [PATCH] Revert "Remove unnecessary code" Fixes gh-24835 --- .../boot/logging/logback/LogbackLoggingSystem.java | 8 ++++++++ .../boot/logging/logback/LogbackLoggingSystemTests.java | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 5c442284c1..f257ff5ee7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -54,6 +54,7 @@ import org.springframework.core.Ordered; import org.springframework.core.SpringProperties; import org.springframework.core.annotation.Order; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ResourceUtils; @@ -147,6 +148,13 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { } LogbackConfigurator configurator = debug ? new DebugLogbackConfigurator(context) : new LogbackConfigurator(context); + Environment environment = initializationContext.getEnvironment(); + context.putProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN, + environment.resolvePlaceholders("${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}")); + context.putProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, environment.resolvePlaceholders( + "${logging.pattern.dateformat:${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}")); + context.putProperty(LoggingSystemProperties.ROLLING_FILE_NAME_PATTERN, environment + .resolvePlaceholders("${logging.pattern.rolling-file-name:${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}")); new DefaultLogbackConfiguration(initializationContext, logFile).apply(configurator); context.setPackagingDataEnabled(true); } 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 ee4ff92d80..9319b12c25 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 @@ -20,9 +20,7 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.EnumSet; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.logging.Handler; import java.util.logging.LogManager; @@ -89,13 +87,10 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { private LoggingInitializationContext initializationContext; - private Set systemPropertyNames; - @BeforeEach void setup() { System.getProperties().remove(LoggingSystemProperties.CONSOLE_LOG_CHARSET); System.getProperties().remove(LoggingSystemProperties.FILE_LOG_CHARSET); - this.systemPropertyNames = new HashSet<>(System.getProperties().keySet()); this.loggingSystem.cleanUp(); this.logger = ((LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory()).getLogger(getClass()); this.environment = new MockEnvironment(); @@ -106,7 +101,6 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { @AfterEach void cleanUp() { - System.getProperties().keySet().retainAll(this.systemPropertyNames); this.loggingSystem.cleanUp(); ((LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory()).stop(); } @@ -318,7 +312,6 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { @Test void testLevelPatternProperty(CapturedOutput output) { this.environment.setProperty("logging.pattern.level", "X%clr(%p)X"); - new LoggingSystemProperties(this.environment).apply(); LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(this.environment); initialize(loggingInitializationContext, null, null); this.logger.info("Hello world"); @@ -521,7 +514,6 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { @Test void testDateformatPatternProperty(CapturedOutput output) { this.environment.setProperty("logging.pattern.dateformat", "yyyy-MM-dd'T'hh:mm:ss.SSSZ"); - new LoggingSystemProperties(this.environment).apply(); LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(this.environment); initialize(loggingInitializationContext, null, null); this.logger.info("Hello world");