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 aace21c061..c8e2aa66c7 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -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 diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index 413740fbc4..537bbed344 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -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( diff --git a/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json index bd48282134..80a1d91811 100644 --- a/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -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": [ { diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index a908cd9844..419cbf6128 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -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,