Remove unnecessary code
Remove code from `LogbackLoggingSystem.loadDefaults` that sets Logback context properties from the Spring Environment. The code should not be required since `LoggingSystemVariables` will have already set system variables for the logging config to use. Closes gh-23767
This commit is contained in:
parent
52f2c27779
commit
fb25104151
|
@ -48,12 +48,10 @@ import org.springframework.boot.logging.LoggerConfiguration;
|
|||
import org.springframework.boot.logging.LoggingInitializationContext;
|
||||
import org.springframework.boot.logging.LoggingSystem;
|
||||
import org.springframework.boot.logging.LoggingSystemFactory;
|
||||
import org.springframework.boot.logging.LoggingSystemProperties;
|
||||
import org.springframework.boot.logging.Slf4JLoggingSystem;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.SpringProperties;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
@ -142,13 +140,6 @@ 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);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ package org.springframework.boot.logging.logback;
|
|||
import java.io.File;
|
||||
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;
|
||||
|
||||
|
@ -79,8 +81,11 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
|
||||
private LoggingInitializationContext initializationContext;
|
||||
|
||||
private Set<Object> systemPropertyNames;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.systemPropertyNames = new HashSet<>(System.getProperties().keySet());
|
||||
this.loggingSystem.cleanUp();
|
||||
this.logger = ((LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory()).getLogger(getClass());
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
|
@ -89,6 +94,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
System.getProperties().keySet().retainAll(this.systemPropertyNames);
|
||||
this.loggingSystem.cleanUp();
|
||||
((LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory()).stop();
|
||||
}
|
||||
|
@ -302,6 +308,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
void testLevelPatternProperty(CapturedOutput output) {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("logging.pattern.level", "X%clr(%p)X");
|
||||
new LoggingSystemProperties(environment).apply();
|
||||
LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(environment);
|
||||
this.loggingSystem.initialize(loggingInitializationContext, null, null);
|
||||
this.logger.info("Hello world");
|
||||
|
@ -514,6 +521,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
void testDateformatPatternProperty(CapturedOutput output) {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("logging.pattern.dateformat", "yyyy-MM-dd'T'hh:mm:ss.SSSZ");
|
||||
new LoggingSystemProperties(environment).apply();
|
||||
LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(environment);
|
||||
this.loggingSystem.initialize(loggingInitializationContext, null, null);
|
||||
this.logger.info("Hello world");
|
||||
|
|
Loading…
Reference in New Issue