Allow to disable debug property

Previously, adding `debug=false` in the environment had no effect as the
mere presence of the property was used to enable the debug mode. This
commit makes sure to also check the value and ignore the property if it
is set to `false`.

The documentation has also been updated to refer to the `trace` property.

Closes gh-5374
pull/5392/head
Stephane Nicoll 9 years ago
parent 8cb602f2d6
commit d22265b13e

@ -1072,9 +1072,14 @@ default `ERROR`, `WARN` and `INFO` level messages are logged. You can also enabl
NOTE: you can also specify `debug=true` in your `application.properties`. NOTE: you can also specify `debug=true` in your `application.properties`.
When the debug mode is enabled, a selection of core loggers (embedded container, Hibernate When the debug mode is enabled, a selection of core loggers (embedded container, Hibernate
and Spring) are configured to output more information. Enabling the debug mode does _not_ and Spring Boot) are configured to output more information. Enabling the debug mode does _not_
configure your application to log all messages with `DEBUG` level. configure your application to log all messages with `DEBUG` level.
Alternatively, you can enable a "`trace`" mode by starting your application with a `--trace`
flag (or `trace=true` in your `application.properties`). This will enable trace logging for a
selection of core loggers (embedded container, Hibernate schema generation and the whole Spring
portfolio).
[[boot-features-logging-color-coded-output]] [[boot-features-logging-color-coded-output]]
==== Color-coded output ==== Color-coded output
If your terminal supports ANSI, color output will be used to aid readability. You can set If your terminal supports ANSI, color output will be used to aid readability. You can set

@ -284,15 +284,20 @@ public class LoggingApplicationListener implements GenericApplicationListener {
private void initializeEarlyLoggingLevel(ConfigurableEnvironment environment) { private void initializeEarlyLoggingLevel(ConfigurableEnvironment environment) {
if (this.parseArgs && this.springBootLogging == null) { if (this.parseArgs && this.springBootLogging == null) {
if (environment.containsProperty("debug")) { if (isSet(environment, "debug")) {
this.springBootLogging = LogLevel.DEBUG; this.springBootLogging = LogLevel.DEBUG;
} }
if (environment.containsProperty("trace")) { if (isSet(environment, "trace")) {
this.springBootLogging = LogLevel.TRACE; this.springBootLogging = LogLevel.TRACE;
} }
} }
} }
private boolean isSet(ConfigurableEnvironment environment, String property) {
String value = environment.getProperty(property);
return !(value == null || value.equals("false"));
}
private void initializeSystem(ConfigurableEnvironment environment, private void initializeSystem(ConfigurableEnvironment environment,
LoggingSystem system, LogFile logFile) { LoggingSystem system, LogFile logFile) {
LoggingInitializationContext initializationContext = new LoggingInitializationContext( LoggingInitializationContext initializationContext = new LoggingInitializationContext(

@ -160,6 +160,13 @@
"type": "java.lang.String", "type": "java.lang.String",
"sourceType": "org.springframework.boot.context.config.ConfigFileApplicationListener", "sourceType": "org.springframework.boot.context.config.ConfigFileApplicationListener",
"description": "Unconditionally activate the specified comma separated profiles." "description": "Unconditionally activate the specified comma separated profiles."
},
{
"name": "trace",
"type": "java.lang.Boolean",
"description": "Enable trace logs.",
"sourceType": "org.springframework.boot.logging.LoggingApplicationListener",
"defaultValue": false
} }
],"hints": [ ],"hints": [
{ {

@ -55,6 +55,7 @@ import static org.hamcrest.Matchers.not;
* @author Dave Syer * @author Dave Syer
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Nicoll
*/ */
public class LoggingApplicationListenerTests { public class LoggingApplicationListenerTests {
@ -231,6 +232,26 @@ public class LoggingApplicationListenerTests {
assertThat(this.outputCapture.toString()).contains("testattrace"); assertThat(this.outputCapture.toString()).contains("testattrace");
} }
@Test
public void disableDebugArg() {
disableDebugTraceArg("debug=false");
}
@Test
public void disableTraceArg() {
disableDebugTraceArg("trace=false");
}
private void disableDebugTraceArg(String... environment) {
EnvironmentTestUtils.addEnvironment(this.context, environment);
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
this.logger.debug("testatdebug");
this.logger.trace("testattrace");
assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
assertThat(this.outputCapture.toString()).doesNotContain("testattrace");
}
@Test @Test
public void parseLevels() throws Exception { public void parseLevels() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, EnvironmentTestUtils.addEnvironment(this.context,

Loading…
Cancel
Save