Skip to content

Commit c2444ae

Browse files
author
Dave Syer
committed
Continue with default location if CONFIG_LOGGING fails
Tomcat in particular sets an environment variable in it's shell scripts that people commonly use to start the container. So if people deploy a war file to a stock Tomcat server they can't override the logging config, even with the default location. With this change at least that should work (for logback and log4j anyway). Tested with logback. See gh-1432
1 parent 47b5904 commit c2444ae

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,20 @@ protected void initialize(ConfigurableEnvironment environment, ClassLoader class
185185
system.initialize(value);
186186
}
187187
catch (Exception ex) {
188-
this.logger.warn("Logging environment value '" + value
189-
+ "' cannot be opened and will be ignored");
188+
this.logger
189+
.warn("Logging environment value '"
190+
+ value
191+
+ "' cannot be opened and will be ignored (using default location instead)");
192+
system.initialize();
190193
}
191194
}
192195
else {
193-
194196
system.initialize();
195-
if (this.springBootLogging != null) {
196-
initializeLogLevel(system, this.springBootLogging);
197-
}
198-
199197
}
200198

199+
if (this.springBootLogging != null) {
200+
initializeLogLevel(system, this.springBootLogging);
201+
}
201202
setLogLevels(system, environment);
202203

203204
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public void overrideConfigDoesNotExist() throws Exception {
126126
this.initializer.initialize(this.context.getEnvironment(),
127127
this.context.getClassLoader());
128128
// Should not throw
129+
this.logger.info("Hello world");
130+
String output = this.outputCapture.toString().trim();
131+
assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
132+
assertFalse("Wrong output:\n" + output, output.contains("???"));
133+
assertTrue(new File(tmpDir() + "/spring.log").exists());
129134
}
130135

131136
@Test

0 commit comments

Comments
 (0)