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.apache.commons.logging.Log;
|
||||||
|
|
||||||
import org.springframework.boot.logging.LoggingSystemProperties;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
@ -109,7 +108,7 @@ class StartupInfoLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPid() {
|
private String getPid() {
|
||||||
return getValue(" with PID ", () -> System.getProperty(LoggingSystemProperties.PID_KEY));
|
return getValue(" with PID ", () -> new ApplicationPid().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getContext() {
|
private String getContext() {
|
||||||
|
|
|
@ -128,10 +128,12 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
||||||
stopAndReset(context);
|
stopAndReset(context);
|
||||||
LogbackConfigurator configurator = new LogbackConfigurator(context);
|
LogbackConfigurator configurator = new LogbackConfigurator(context);
|
||||||
Environment environment = initializationContext.getEnvironment();
|
Environment environment = initializationContext.getEnvironment();
|
||||||
context.putProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN, environment.resolvePlaceholders(
|
context.putProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN,
|
||||||
"${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
|
environment.resolvePlaceholders(
|
||||||
context.putProperty(LoggingSystemProperties.LOG_DATEFORMAT_PATTERN, environment.resolvePlaceholders(
|
"${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"));
|
||||||
"${logging.pattern.dateformat:${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}"));
|
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)
|
new DefaultLogbackConfiguration(initializationContext, logFile)
|
||||||
.apply(configurator);
|
.apply(configurator);
|
||||||
context.setPackagingDataEnabled(true);
|
context.setPackagingDataEnabled(true);
|
||||||
|
|
|
@ -482,13 +482,18 @@ public class LoggingApplicationListenerTests {
|
||||||
"logging.pattern.file=file", "logging.pattern.level=level");
|
"logging.pattern.file=file", "logging.pattern.level=level");
|
||||||
this.initializer.initialize(this.context.getEnvironment(),
|
this.initializer.initialize(this.context.getEnvironment(),
|
||||||
this.context.getClassLoader());
|
this.context.getClassLoader());
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN)).isEqualTo("console");
|
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.FILE_LOG_PATTERN)).isEqualTo("file");
|
.isEqualTo("console");
|
||||||
|
assertThat(System.getProperty(LoggingSystemProperties.FILE_LOG_PATTERN))
|
||||||
|
.isEqualTo("file");
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.EXCEPTION_CONVERSION_WORD))
|
assertThat(System.getProperty(LoggingSystemProperties.EXCEPTION_CONVERSION_WORD))
|
||||||
.isEqualTo("conversion");
|
.isEqualTo("conversion");
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo("target/log");
|
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN)).isEqualTo("level");
|
.isEqualTo("target/log");
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("path");
|
assertThat(System.getProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN))
|
||||||
|
.isEqualTo("level");
|
||||||
|
assertThat(System.getProperty(LoggingSystemProperties.LOG_PATH))
|
||||||
|
.isEqualTo("path");
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.PID_KEY)).isNotNull();
|
assertThat(System.getProperty(LoggingSystemProperties.PID_KEY)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +504,8 @@ public class LoggingApplicationListenerTests {
|
||||||
"logging.pattern.console=console ${pid}");
|
"logging.pattern.console=console ${pid}");
|
||||||
this.initializer.initialize(this.context.getEnvironment(),
|
this.initializer.initialize(this.context.getEnvironment(),
|
||||||
this.context.getClassLoader());
|
this.context.getClassLoader());
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN)).isEqualTo("console ${pid}");
|
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
|
||||||
|
.isEqualTo("console ${pid}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -51,7 +51,8 @@ public class LogFileTests {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
logFile.applyTo(properties);
|
logFile.applyTo(properties);
|
||||||
assertThat(logFile.toString()).isEqualTo("log.file");
|
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();
|
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +63,10 @@ public class LogFileTests {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
logFile.applyTo(properties);
|
logFile.applyTo(properties);
|
||||||
assertThat(logFile.toString()).isEqualTo("logpath/spring.log");
|
assertThat(logFile.toString()).isEqualTo("logpath/spring.log");
|
||||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo("logpath/spring.log");
|
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("logpath");
|
.isEqualTo("logpath/spring.log");
|
||||||
|
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH))
|
||||||
|
.isEqualTo("logpath");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -73,8 +76,10 @@ public class LogFileTests {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
logFile.applyTo(properties);
|
logFile.applyTo(properties);
|
||||||
assertThat(logFile.toString()).isEqualTo("log.file");
|
assertThat(logFile.toString()).isEqualTo("log.file");
|
||||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo("log.file");
|
assertThat(properties.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||||
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("logpath");
|
.isEqualTo("log.file");
|
||||||
|
assertThat(properties.getProperty(LoggingSystemProperties.LOG_PATH))
|
||||||
|
.isEqualTo("logpath");
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyResolver getPropertyResolver(String file, String path) {
|
private PropertyResolver getPropertyResolver(String file, String path) {
|
||||||
|
|
|
@ -420,7 +420,8 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
||||||
LogFile logFile = getLogFile(tmpDir() + "/example.log", null, false);
|
LogFile logFile = getLogFile(tmpDir() + "/example.log", null, false);
|
||||||
this.loggingSystem.initialize(this.initializationContext,
|
this.loggingSystem.initialize(this.initializationContext,
|
||||||
"classpath:logback-nondefault.xml", logFile);
|
"classpath:logback-nondefault.xml", logFile);
|
||||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE)).endsWith("example.log");
|
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE))
|
||||||
|
.endsWith("example.log");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue