From 32b32b714275d0efaa1f5afba10e88e09101f224 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 19 Oct 2015 14:37:12 +0200 Subject: [PATCH] Notify the use of logback specific system property Logback documentation explains how to initialize the logging system and namely how the `logback.configurationFile` system property can be used to specify the configuration file to use. Spring Boot has an abstraction on top of that. A user can define the `logging.path` property regardless of the logging infrastructure it is using. Users following the logback documentation can be confused at first so we're not logging a warning when we found out that the logback specific property has been specified. Closes gh-2382 --- .../src/main/asciidoc/spring-boot-features.adoc | 3 +++ .../logging/logback/LogbackLoggingSystem.java | 7 +++++++ .../logback/LogbackLoggingSystemTests.java | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 56ddb31bc1..e6a7262662 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -1019,6 +1019,9 @@ NOTE: The logging system is initialized early in the application lifecycle and a logging properties will not be found in property files loaded via `@PropertySource` annotations. +TIP: Logging properties are independent of the actual logging infrastructure. As a +result, specific configuration keys (such as `logback.configurationFile` for Logback) +are not managed by spring Boot. [[boot-features-custom-log-levels]] diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 40501d35a8..bb3a17fd64 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -56,6 +56,8 @@ import ch.qos.logback.core.status.Status; */ public class LogbackLoggingSystem extends Slf4JLoggingSystem { + private static final String CONFIGURATION_FILE_PROPERTY = "logback.configurationFile"; + private static final Map LEVELS; static { @@ -102,6 +104,11 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { String configLocation, LogFile logFile) { getLogger(null).getLoggerContext().getTurboFilterList().remove(FILTER); super.initialize(initializationContext, configLocation, logFile); + if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) { + getLogger(LogbackLoggingSystem.class.getName()).warn( + "Ignoring '"+CONFIGURATION_FILE_PROPERTY+"' system property. " + + "Please use 'logging.path' instead."); + } } @Override diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index e16540ef93..9795fb1268 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -141,6 +141,21 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { assertFalse(new File(tmpDir() + "/tmp.log").exists()); } + @Test + public void testLogbackSpecificSystemProperty() throws Exception { + System.setProperty("logback.configurationFile", "/foo/my-file.xml"); + try { + this.loggingSystem.beforeInitialize(); + this.loggingSystem.initialize(this.initializationContext, null, null); + String output = this.output.toString().trim(); + assertTrue("Wrong output:\n" + output, output.contains("Ignoring " + + "'logback.configurationFile' system property. Please use 'logging.path' instead.")); + } + finally { + System.clearProperty("logback.configurationFile"); + } + } + @Test(expected = IllegalStateException.class) public void testNonexistentConfigLocation() throws Exception { this.loggingSystem.beforeInitialize();