From f1489e41ec119655f96078989ba7ab6b58b40ef9 Mon Sep 17 00:00:00 2001 From: Mark Bigler Date: Fri, 15 Nov 2019 11:31:25 +0100 Subject: [PATCH 1/2] Fix logging in CloudFoundryVcapEnvironmentPostProcessor See gh-19027 --- .../CloudFoundryVcapEnvironmentPostProcessor.java | 15 ++++++++++----- .../src/main/resources/META-INF/spring.factories | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java index f038288f26..b34656d0b7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java @@ -22,14 +22,14 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.boot.SpringApplication; import org.springframework.boot.context.config.ConfigFileApplicationListener; +import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.boot.json.JsonParser; import org.springframework.boot.json.JsonParserFactory; +import org.springframework.boot.logging.DeferredLog; +import org.springframework.context.ApplicationListener; import org.springframework.core.Ordered; import org.springframework.core.env.CommandLinePropertySource; import org.springframework.core.env.ConfigurableEnvironment; @@ -89,9 +89,9 @@ import org.springframework.util.StringUtils; * @author Andy Wilkinson * @since 1.3.0 */ -public class CloudFoundryVcapEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { +public class CloudFoundryVcapEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered, ApplicationListener { - private static final Log logger = LogFactory.getLog(CloudFoundryVcapEnvironmentPostProcessor.class); + private static final DeferredLog logger = new DeferredLog(); private static final String VCAP_APPLICATION = "VCAP_APPLICATION"; @@ -127,6 +127,11 @@ public class CloudFoundryVcapEnvironmentPostProcessor implements EnvironmentPost } } + @Override + public void onApplicationEvent(ApplicationPreparedEvent event) { + logger.switchTo(CloudFoundryVcapEnvironmentPostProcessor.class); + } + private void addWithPrefix(Properties properties, Properties other, String prefix) { for (String key : other.stringPropertyNames()) { String prefixed = prefix + key; diff --git a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories index 0e09bea33e..e419d3e7e3 100644 --- a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories @@ -22,6 +22,7 @@ org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer org.springframework.context.ApplicationListener=\ org.springframework.boot.ClearCachesApplicationListener,\ org.springframework.boot.builder.ParentContextCloserApplicationListener,\ +org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\ org.springframework.boot.context.FileEncodingApplicationListener,\ org.springframework.boot.context.config.AnsiOutputApplicationListener,\ org.springframework.boot.context.config.ConfigFileApplicationListener,\ From b23a3712c6799c66c86ae03e2d17041ee25a1579 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 21 Nov 2019 13:41:47 +0100 Subject: [PATCH 2/2] Polish "Fix logging in CloudFoundryVcapEnvironmentPostProcessor" See gh-19027 --- .../boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java index b34656d0b7..587cd0eedc 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java @@ -89,7 +89,8 @@ import org.springframework.util.StringUtils; * @author Andy Wilkinson * @since 1.3.0 */ -public class CloudFoundryVcapEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered, ApplicationListener { +public class CloudFoundryVcapEnvironmentPostProcessor + implements EnvironmentPostProcessor, Ordered, ApplicationListener { private static final DeferredLog logger = new DeferredLog();