Skip to content

Commit c2221b9

Browse files
committed
Merge pull request #19027 from markbigler
* pr/19027: Polish "Fix logging in CloudFoundryVcapEnvironmentPostProcessor" Fix logging in CloudFoundryVcapEnvironmentPostProcessor Closes gh-19027
2 parents 3c3614d + b23a371 commit c2221b9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
import java.util.Map;
2323
import java.util.Properties;
2424

25-
import org.apache.commons.logging.Log;
26-
import org.apache.commons.logging.LogFactory;
27-
2825
import org.springframework.boot.SpringApplication;
2926
import org.springframework.boot.context.config.ConfigFileApplicationListener;
27+
import org.springframework.boot.context.event.ApplicationPreparedEvent;
3028
import org.springframework.boot.env.EnvironmentPostProcessor;
3129
import org.springframework.boot.json.JsonParser;
3230
import org.springframework.boot.json.JsonParserFactory;
31+
import org.springframework.boot.logging.DeferredLog;
32+
import org.springframework.context.ApplicationListener;
3333
import org.springframework.core.Ordered;
3434
import org.springframework.core.env.CommandLinePropertySource;
3535
import org.springframework.core.env.ConfigurableEnvironment;
@@ -89,9 +89,10 @@
8989
* @author Andy Wilkinson
9090
* @since 1.3.0
9191
*/
92-
public class CloudFoundryVcapEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
92+
public class CloudFoundryVcapEnvironmentPostProcessor
93+
implements EnvironmentPostProcessor, Ordered, ApplicationListener<ApplicationPreparedEvent> {
9394

94-
private static final Log logger = LogFactory.getLog(CloudFoundryVcapEnvironmentPostProcessor.class);
95+
private static final DeferredLog logger = new DeferredLog();
9596

9697
private static final String VCAP_APPLICATION = "VCAP_APPLICATION";
9798

@@ -127,6 +128,11 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
127128
}
128129
}
129130

131+
@Override
132+
public void onApplicationEvent(ApplicationPreparedEvent event) {
133+
logger.switchTo(CloudFoundryVcapEnvironmentPostProcessor.class);
134+
}
135+
130136
private void addWithPrefix(Properties properties, Properties other, String prefix) {
131137
for (String key : other.stringPropertyNames()) {
132138
String prefixed = prefix + key;

spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
2222
org.springframework.context.ApplicationListener=\
2323
org.springframework.boot.ClearCachesApplicationListener,\
2424
org.springframework.boot.builder.ParentContextCloserApplicationListener,\
25+
org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,\
2526
org.springframework.boot.context.FileEncodingApplicationListener,\
2627
org.springframework.boot.context.config.AnsiOutputApplicationListener,\
2728
org.springframework.boot.context.config.ConfigFileApplicationListener,\

0 commit comments

Comments
 (0)