Set PID early for logging

Set PID early in the initialization process to ensure log enties are
not written without an ID.
pull/9/head
Phillip Webb 12 years ago
parent 1bec676ca1
commit 50109d4ace

@ -82,6 +82,9 @@ public class LoggingApplicationContextInitializer implements
@Override @Override
public void initialize(SpringApplication springApplication) { public void initialize(SpringApplication springApplication) {
if (System.getProperty("PID") == null) {
System.setProperty("PID", getPid());
}
LoggingSystem.get(springApplication.getClass().getClassLoader()) LoggingSystem.get(springApplication.getClass().getClassLoader())
.beforeInitialize(); .beforeInitialize();
} }
@ -103,10 +106,6 @@ public class LoggingApplicationContextInitializer implements
} }
} }
if (System.getProperty("PID") == null) {
System.setProperty("PID", getPid());
}
LoggingSystem system = LoggingSystem.get(applicationContext.getClassLoader()); LoggingSystem system = LoggingSystem.get(applicationContext.getClassLoader());
// User specified configuration // User specified configuration

@ -29,6 +29,7 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.springframework.bootstrap.SpringApplication;
import org.springframework.bootstrap.logging.java.JavaLoggingSystem; import org.springframework.bootstrap.logging.java.JavaLoggingSystem;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
@ -61,6 +62,7 @@ public class LoggingApplicationContextInitializerTests {
System.setOut(new PrintStream(this.output)); System.setOut(new PrintStream(this.output));
LogManager.getLogManager().readConfiguration( LogManager.getLogManager().readConfiguration(
JavaLoggingSystem.class.getResourceAsStream("logging.properties")); JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
this.initializer.initialize(new SpringApplication());
} }
@After @After

Loading…
Cancel
Save