From 50109d4ace31c9487cfc04b8435b8053d980e1a1 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 17 Jul 2013 23:25:24 -0700 Subject: [PATCH] Set PID early for logging Set PID early in the initialization process to ensure log enties are not written without an ID. --- .../initializer/LoggingApplicationContextInitializer.java | 7 +++---- .../LoggingApplicationContextInitializerTests.java | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializer.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializer.java index 73ad5448f7..1d48a1d1b8 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializer.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializer.java @@ -82,6 +82,9 @@ public class LoggingApplicationContextInitializer implements @Override public void initialize(SpringApplication springApplication) { + if (System.getProperty("PID") == null) { + System.setProperty("PID", getPid()); + } LoggingSystem.get(springApplication.getClass().getClassLoader()) .beforeInitialize(); } @@ -103,10 +106,6 @@ public class LoggingApplicationContextInitializer implements } } - if (System.getProperty("PID") == null) { - System.setProperty("PID", getPid()); - } - LoggingSystem system = LoggingSystem.get(applicationContext.getClassLoader()); // User specified configuration diff --git a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializerTests.java b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializerTests.java index 11c63db7fc..43de38cb9b 100644 --- a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializerTests.java +++ b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/initializer/LoggingApplicationContextInitializerTests.java @@ -29,6 +29,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.springframework.bootstrap.SpringApplication; import org.springframework.bootstrap.logging.java.JavaLoggingSystem; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.env.PropertySource; @@ -61,6 +62,7 @@ public class LoggingApplicationContextInitializerTests { System.setOut(new PrintStream(this.output)); LogManager.getLogManager().readConfiguration( JavaLoggingSystem.class.getResourceAsStream("logging.properties")); + this.initializer.initialize(new SpringApplication()); } @After