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
This commit is contained in:
		
							parent
							
								
									e4230e61d7
								
							
						
					
					
						commit
						32b32b7142
					
				|  | @ -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` | logging properties will not be found in property files loaded via `@PropertySource` | ||||||
| annotations. | 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]] | [[boot-features-custom-log-levels]] | ||||||
|  |  | ||||||
|  | @ -56,6 +56,8 @@ import ch.qos.logback.core.status.Status; | ||||||
|  */ |  */ | ||||||
| public class LogbackLoggingSystem extends Slf4JLoggingSystem { | public class LogbackLoggingSystem extends Slf4JLoggingSystem { | ||||||
| 
 | 
 | ||||||
|  | 	private static final String CONFIGURATION_FILE_PROPERTY = "logback.configurationFile"; | ||||||
|  | 
 | ||||||
| 	private static final Map<LogLevel, Level> LEVELS; | 	private static final Map<LogLevel, Level> LEVELS; | ||||||
| 
 | 
 | ||||||
| 	static { | 	static { | ||||||
|  | @ -102,6 +104,11 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { | ||||||
| 			String configLocation, LogFile logFile) { | 			String configLocation, LogFile logFile) { | ||||||
| 		getLogger(null).getLoggerContext().getTurboFilterList().remove(FILTER); | 		getLogger(null).getLoggerContext().getTurboFilterList().remove(FILTER); | ||||||
| 		super.initialize(initializationContext, configLocation, logFile); | 		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 | 	@Override | ||||||
|  |  | ||||||
|  | @ -141,6 +141,21 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { | ||||||
| 		assertFalse(new File(tmpDir() + "/tmp.log").exists()); | 		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) | 	@Test(expected = IllegalStateException.class) | ||||||
| 	public void testNonexistentConfigLocation() throws Exception { | 	public void testNonexistentConfigLocation() throws Exception { | ||||||
| 		this.loggingSystem.beforeInitialize(); | 		this.loggingSystem.beforeInitialize(); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue