Commit 32b32b71 authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent e4230e61
......@@ -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]]
......
......@@ -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<LogLevel, Level> 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
......
......@@ -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();
......
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