Add a call to update log levels during bootstrap
Since the bootstrap customizations are applied in ApplicationContextInitializers they come too late to affect the logging levels. But the LoggingRebinder listener isn't installed yet, and the context is not ready for events to be published. So to get the logging changes in as early as possible we actually need to explicitly apply them in the property source initializer as soon as the remote properties are available. Fixes gh-74, fixes gh-75
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.cloud.bootstrap.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -31,6 +32,8 @@ import org.springframework.cloud.bootstrap.BootstrapApplicationListener;
|
||||
import org.springframework.cloud.config.client.ConfigClientProperties;
|
||||
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
|
||||
import org.springframework.cloud.config.client.PropertySourceLocator;
|
||||
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
|
||||
import org.springframework.cloud.logging.LoggingRebinder;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -90,16 +93,26 @@ public class PropertySourceBootstrapConfiguration implements
|
||||
propertySources.remove(BOOTSTRAP_PROPERTY_SOURCE_NAME);
|
||||
}
|
||||
insertPropertySources(propertySources, composite);
|
||||
setLogLevels(applicationContext.getEnvironment());
|
||||
}
|
||||
}
|
||||
|
||||
private void setLogLevels(ConfigurableEnvironment environment) {
|
||||
LoggingRebinder rebinder = new LoggingRebinder();
|
||||
rebinder.setEnvironment(environment);
|
||||
// We can't fire the event in the ApplicationContext here (too early), but we can
|
||||
// create our own listener and poke it (it doesn't need the key changes)
|
||||
rebinder.onApplicationEvent(new EnvironmentChangeEvent(Collections
|
||||
.<String> emptySet()));
|
||||
}
|
||||
|
||||
private void insertPropertySources(MutablePropertySources propertySources,
|
||||
CompositePropertySource composite) {
|
||||
MutablePropertySources incoming = new MutablePropertySources();
|
||||
incoming.addFirst(composite);
|
||||
PropertySourceBootstrapProperties remoteProperties = new PropertySourceBootstrapProperties();
|
||||
new RelaxedDataBinder(remoteProperties, "spring.cloud.config").bind(new PropertySourcesPropertyValues(
|
||||
incoming));
|
||||
new RelaxedDataBinder(remoteProperties, "spring.cloud.config")
|
||||
.bind(new PropertySourcesPropertyValues(incoming));
|
||||
if (!remoteProperties.isAllowOverride()
|
||||
|| remoteProperties.isOverrideSystemProperties()) {
|
||||
propertySources.addFirst(composite);
|
||||
|
||||
Reference in New Issue
Block a user