Browse Source

Broaden LoggingApplicationListener ignores

Update `LoggingApplicationListener` to ignore all `-D` prefixed
property values. As well as catching the Azure use-case, this update
now means Spring Boot application can start when Tomcat is missing
`CATALINA_BASE\conf\logging.properties` and sets the value `-Dnop`.

Closes gh-7639
pull/7721/head
Chaouki Dhib 9 years ago committed by Phillip Webb
parent
commit
2ea4d4b1d9
  1. 7
      spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java
  2. 12
      spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java

7
spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java

@ -314,12 +314,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { @@ -314,12 +314,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
}
private boolean ignoreLogConfig(String logConfig) {
return !StringUtils.hasLength(logConfig)
|| isDefaultAzureLoggingConfig(logConfig);
}
private boolean isDefaultAzureLoggingConfig(String candidate) {
return candidate.startsWith("-Djava.util.logging.config.file=");
return !StringUtils.hasLength(logConfig) || logConfig.startsWith("-D");
}
private void initializeFinalLoggingLevels(ConfigurableEnvironment environment,

12
spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java

@ -162,6 +162,18 @@ public class LoggingApplicationListenerTests { @@ -162,6 +162,18 @@ public class LoggingApplicationListenerTests {
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
}
@Test
public void tomcatNopLoggingConfigDoesNotCauseAFailure() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.config: -Dnop");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
this.logger.info("Hello world");
String output = this.outputCapture.toString().trim();
assertThat(output).contains("Hello world").doesNotContain("???");
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
}
@Test
public void overrideConfigBroken() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,

Loading…
Cancel
Save