From c2444aecd6cd92d6d5d9ba514081433d4cb85635 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 28 Aug 2014 07:50:46 +0100 Subject: [PATCH] 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 --- .../boot/logging/LoggingApplicationListener.java | 15 ++++++++------- .../logging/LoggingApplicationListenerTests.java | 5 +++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index d7806c0649..c47bef4c57 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -185,19 +185,20 @@ public class LoggingApplicationListener implements SmartApplicationListener { system.initialize(value); } catch (Exception ex) { - this.logger.warn("Logging environment value '" + value - + "' cannot be opened and will be ignored"); + this.logger + .warn("Logging environment value '" + + value + + "' cannot be opened and will be ignored (using default location instead)"); + system.initialize(); } } else { - system.initialize(); - if (this.springBootLogging != null) { - initializeLogLevel(system, this.springBootLogging); - } - } + if (this.springBootLogging != null) { + initializeLogLevel(system, this.springBootLogging); + } setLogLevels(system, environment); } diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index 88b6c49431..3735f18d13 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -126,6 +126,11 @@ public class LoggingApplicationListenerTests { this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); // Should not throw + this.logger.info("Hello world"); + String output = this.outputCapture.toString().trim(); + assertTrue("Wrong output:\n" + output, output.contains("Hello world")); + assertFalse("Wrong output:\n" + output, output.contains("???")); + assertTrue(new File(tmpDir() + "/spring.log").exists()); } @Test