Revert "Remove unnecessary code"

Fixes gh-24835
pull/24986/head
Madhura Bhave 4 years ago
parent 716dce3859
commit 68fc2329c8

@ -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);
}

@ -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<Object> 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");

Loading…
Cancel
Save