Commit d22265b1 authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent 8cb602f2
......@@ -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`.
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.
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]]
==== Color-coded output
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) {
if (this.parseArgs && this.springBootLogging == null) {
if (environment.containsProperty("debug")) {
if (isSet(environment, "debug")) {
this.springBootLogging = LogLevel.DEBUG;
}
if (environment.containsProperty("trace")) {
if (isSet(environment, "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,
LoggingSystem system, LogFile logFile) {
LoggingInitializationContext initializationContext = new LoggingInitializationContext(
......
......@@ -160,6 +160,13 @@
"type": "java.lang.String",
"sourceType": "org.springframework.boot.context.config.ConfigFileApplicationListener",
"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": [
{
......
......@@ -55,6 +55,7 @@ import static org.hamcrest.Matchers.not;
* @author Dave Syer
* @author Phillip Webb
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public class LoggingApplicationListenerTests {
......@@ -231,6 +232,26 @@ public class LoggingApplicationListenerTests {
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
public void parseLevels() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
......
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