Commit a07f0272 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 04c3e997
...@@ -141,7 +141,19 @@ public class LoggingApplicationListener implements SmartApplicationListener { ...@@ -141,7 +141,19 @@ public class LoggingApplicationListener implements SmartApplicationListener {
* {@link Environment} and the classpath. * {@link Environment} and the classpath.
*/ */
protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) { protected void initialize(ConfigurableEnvironment environment, ClassLoader classLoader) {
initializeEarlyLoggingLevel(environment);
cleanLogTempProperty();
LoggingSystem system = LoggingSystem.get(classLoader);
boolean systemEnvironmentChanged = mapSystemPropertiesFromSpring(environment);
if (systemEnvironmentChanged) {
// Re-initialize the defaults in case the system Environment changed
system.beforeInitialize();
}
initializeSystem(environment, system);
initializeFinalLoggingLevels(environment, system);
}
private void initializeEarlyLoggingLevel(ConfigurableEnvironment environment) {
if (this.parseArgs && this.springBootLogging == null) { if (this.parseArgs && this.springBootLogging == null) {
if (environment.containsProperty("debug")) { if (environment.containsProperty("debug")) {
this.springBootLogging = LogLevel.DEBUG; this.springBootLogging = LogLevel.DEBUG;
...@@ -150,7 +162,9 @@ public class LoggingApplicationListener implements SmartApplicationListener { ...@@ -150,7 +162,9 @@ public class LoggingApplicationListener implements SmartApplicationListener {
this.springBootLogging = LogLevel.TRACE; this.springBootLogging = LogLevel.TRACE;
} }
} }
}
private void cleanLogTempProperty() {
// Logback won't read backslashes so add a clean path for it to use // Logback won't read backslashes so add a clean path for it to use
if (!StringUtils.hasLength(System.getProperty("LOG_TEMP"))) { if (!StringUtils.hasLength(System.getProperty("LOG_TEMP"))) {
String path = System.getProperty("java.io.tmpdir"); String path = System.getProperty("java.io.tmpdir");
...@@ -160,24 +174,24 @@ public class LoggingApplicationListener implements SmartApplicationListener { ...@@ -160,24 +174,24 @@ public class LoggingApplicationListener implements SmartApplicationListener {
} }
System.setProperty("LOG_TEMP", path); System.setProperty("LOG_TEMP", path);
} }
}
boolean environmentChanged = false; private boolean mapSystemPropertiesFromSpring(Environment environment) {
boolean changed = false;
for (Map.Entry<String, String> mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING for (Map.Entry<String, String> mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING
.entrySet()) { .entrySet()) {
if (environment.containsProperty(mapping.getKey())) { String springName = mapping.getKey();
System.setProperty(mapping.getValue(), String systemName = mapping.getValue();
environment.getProperty(mapping.getKey())); if (environment.containsProperty(springName)) {
environmentChanged = true; System.setProperty(systemName, environment.getProperty(springName));
changed = true;
} }
} }
return changed;
}
LoggingSystem system = LoggingSystem.get(classLoader); private void initializeSystem(ConfigurableEnvironment environment,
LoggingSystem system) {
if (environmentChanged) {
// Re-initialize the defaults in case the Environment changed
system.beforeInitialize();
}
// User specified configuration
if (environment.containsProperty("logging.config")) { if (environment.containsProperty("logging.config")) {
String value = environment.getProperty("logging.config"); String value = environment.getProperty("logging.config");
try { try {
...@@ -185,22 +199,23 @@ public class LoggingApplicationListener implements SmartApplicationListener { ...@@ -185,22 +199,23 @@ public class LoggingApplicationListener implements SmartApplicationListener {
system.initialize(value); system.initialize(value);
} }
catch (Exception ex) { catch (Exception ex) {
this.logger this.logger.warn("Logging environment value '" + value
.warn("Logging environment value '" + "' cannot be opened and will be ignored "
+ value + "(using default location instead)");
+ "' cannot be opened and will be ignored (using default location instead)");
system.initialize(); system.initialize();
} }
} }
else { else {
system.initialize(); system.initialize();
} }
}
private void initializeFinalLoggingLevels(ConfigurableEnvironment environment,
LoggingSystem system) {
if (this.springBootLogging != null) { if (this.springBootLogging != null) {
initializeLogLevel(system, this.springBootLogging); initializeLogLevel(system, this.springBootLogging);
} }
setLogLevels(system, environment); setLogLevels(system, environment);
} }
public void setLogLevels(LoggingSystem system, Environment environment) { public void setLogLevels(LoggingSystem system, Environment environment) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment