Polish "Use LoggingSystemProperties constants"
Closes gh-11240
This commit is contained in:
parent
4c5de416ef
commit
54369a72ca
|
@ -22,7 +22,6 @@ import java.util.concurrent.Callable;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.boot.logging.LoggingSystemProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
@ -109,7 +108,7 @@ class StartupInfoLogger {
|
|||
}
|
||||
|
||||
private String getPid() {
|
||||
return getValue(" with PID ", () -> System.getProperty(LoggingSystemProperties.PID_KEY));
|
||||
return getValue(" with PID ", () -> new ApplicationPid().toString());
|
||||
}
|
||||
|
||||
private String getContext() {
|
||||
|
|
|
@ -128,10 +128,12 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|||
stopAndReset(context);
|
||||
LogbackConfigurator configurator = 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.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}}"));
|
||||
new DefaultLogbackConfiguration(initializationContext, logFile)
|
||||
.apply(configurator);
|
||||
context.setPackagingDataEnabled(true);
|
||||
|
|
|
@ -482,13 +482,18 @@ public class LoggingApplicationListenerTests {
|
|||
"logging.pattern.file=file", "logging.pattern.level=level");
|
||||
this.initializer.initialize(this.context.getEnvironment(),
|
||||
this.context.getClassLoader());
|
||||
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN)).isEqualTo("console");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.FILE_LOG_PATTERN)).isEqualTo("file");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
|
||||
.isEqualTo("console");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.FILE_LOG_PATTERN))
|
||||
.isEqualTo("file");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.EXCEPTION_CONVERSION_WORD))
|
||||
.isEqualTo("conversion");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo("target/log");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN)).isEqualTo("level");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("path");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||
.isEqualTo("target/log");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN))
|
||||
.isEqualTo("level");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_PATH))
|
||||
.isEqualTo("path");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.PID_KEY)).isNotNull();
|
||||
}
|
||||
|
||||
|
@ -499,7 +504,8 @@ public class LoggingApplicationListenerTests {
|
|||
"logging.pattern.console=console ${pid}");
|
||||
this.initializer.initialize(this.context.getEnvironment(),
|
||||
this.context.getClassLoader());
|
||||
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN)).isEqualTo("console ${pid}");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
|
||||
.isEqualTo("console ${pid}");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -51,7 +51,8 @@ public class LogFileTests {
|
|||
Properties properties = new Properties();
|
||||
logFile.applyTo(properties);
|
||||
assertThat(logFile.toString()).isEqualTo("log.file");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo("log.file");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||
.isEqualTo("log.file");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH)).isNull();
|
||||
}
|
||||
|
||||
|
@ -62,8 +63,10 @@ public class LogFileTests {
|
|||
Properties properties = new Properties();
|
||||
logFile.applyTo(properties);
|
||||
assertThat(logFile.toString()).isEqualTo("logpath/spring.log");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo("logpath/spring.log");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("logpath");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||
.isEqualTo("logpath/spring.log");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH))
|
||||
.isEqualTo("logpath");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,8 +76,10 @@ public class LogFileTests {
|
|||
Properties properties = new Properties();
|
||||
logFile.applyTo(properties);
|
||||
assertThat(logFile.toString()).isEqualTo("log.file");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo("log.file");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("logpath");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||
.isEqualTo("log.file");
|
||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH))
|
||||
.isEqualTo("logpath");
|
||||
}
|
||||
|
||||
private PropertyResolver getPropertyResolver(String file, String path) {
|
||||
|
|
|
@ -420,7 +420,8 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
|||
LogFile logFile = getLogFile(tmpDir() + "/example.log", null, false);
|
||||
this.loggingSystem.initialize(this.initializationContext,
|
||||
"classpath:logback-nondefault.xml", logFile);
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE)).endsWith("example.log");
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||
.endsWith("example.log");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue