Skip to content

Commit cef635d

Browse files
committed
Reinstate devtools debug logging with opt-out
Reinstate `web` logging when devtools is in use, making use of the new logging groups support. Devtools now also logs an `INFO` message informing that properties defaults are offers an easy way to disable them. Closes gh-14450
1 parent c4caf27 commit cef635d

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java

+32-20
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23+
import org.apache.commons.logging.Log;
24+
2325
import org.springframework.boot.SpringApplication;
26+
import org.springframework.boot.devtools.logger.DevToolsLogFactory;
2427
import org.springframework.boot.devtools.restart.Restarter;
2528
import org.springframework.boot.env.EnvironmentPostProcessor;
2629
import org.springframework.core.Ordered;
2730
import org.springframework.core.annotation.Order;
2831
import org.springframework.core.env.ConfigurableEnvironment;
2932
import org.springframework.core.env.Environment;
3033
import org.springframework.core.env.MapPropertySource;
31-
import org.springframework.core.env.PropertySource;
3234

3335
/**
3436
* {@link EnvironmentPostProcessor} to add properties that make sense when working at
@@ -42,33 +44,40 @@
4244
@Order(Ordered.LOWEST_PRECEDENCE)
4345
public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
4446

47+
private static final Log logger = DevToolsLogFactory
48+
.getLog(DevToolsPropertyDefaultsPostProcessor.class);
49+
50+
private static final String ENABLED = "spring.devtools.add-properties";
51+
4552
private static final Map<String, Object> PROPERTIES;
4653

4754
static {
48-
Map<String, Object> devToolsProperties = new HashMap<>();
49-
devToolsProperties.put("spring.thymeleaf.cache", "false");
50-
devToolsProperties.put("spring.freemarker.cache", "false");
51-
devToolsProperties.put("spring.groovy.template.cache", "false");
52-
devToolsProperties.put("spring.mustache.cache", "false");
53-
devToolsProperties.put("server.servlet.session.persistent", "true");
54-
devToolsProperties.put("spring.h2.console.enabled", "true");
55-
devToolsProperties.put("spring.resources.cache.period", "0");
56-
devToolsProperties.put("spring.resources.chain.cache", "false");
57-
devToolsProperties.put("spring.template.provider.cache", "false");
58-
devToolsProperties.put("spring.mvc.log-resolved-exception", "true");
59-
devToolsProperties.put("server.error.include-stacktrace", "ALWAYS");
60-
devToolsProperties.put("server.servlet.jsp.init-parameters.development", "true");
61-
devToolsProperties.put("spring.reactor.stacktrace-mode.enabled", "true");
62-
PROPERTIES = Collections.unmodifiableMap(devToolsProperties);
55+
Map<String, Object> properties = new HashMap<>();
56+
properties.put("spring.thymeleaf.cache", "false");
57+
properties.put("spring.freemarker.cache", "false");
58+
properties.put("spring.groovy.template.cache", "false");
59+
properties.put("spring.mustache.cache", "false");
60+
properties.put("server.servlet.session.persistent", "true");
61+
properties.put("spring.h2.console.enabled", "true");
62+
properties.put("spring.resources.cache.period", "0");
63+
properties.put("spring.resources.chain.cache", "false");
64+
properties.put("spring.template.provider.cache", "false");
65+
properties.put("spring.mvc.log-resolved-exception", "true");
66+
properties.put("server.error.include-stacktrace", "ALWAYS");
67+
properties.put("server.servlet.jsp.init-parameters.development", "true");
68+
properties.put("spring.reactor.stacktrace-mode.enabled", "true");
69+
properties.put("logging.level.web", "debug");
70+
PROPERTIES = Collections.unmodifiableMap(properties);
6371
}
6472

6573
@Override
6674
public void postProcessEnvironment(ConfigurableEnvironment environment,
6775
SpringApplication application) {
6876
if (isLocalApplication(environment) && canAddProperties(environment)) {
69-
PropertySource<?> propertySource = new MapPropertySource("refresh",
70-
PROPERTIES);
71-
environment.getPropertySources().addLast(propertySource);
77+
logger.info("Devtools property and logging defaults active! Set '" + ENABLED
78+
+ "' to 'false' to disable");
79+
environment.getPropertySources()
80+
.addLast(new MapPropertySource("devtools", PROPERTIES));
7281
}
7382
}
7483

@@ -77,7 +86,10 @@ private boolean isLocalApplication(ConfigurableEnvironment environment) {
7786
}
7887

7988
private boolean canAddProperties(Environment environment) {
80-
return isRestarterInitialized() || isRemoteRestartEnabled(environment);
89+
if (environment.getProperty(ENABLED, Boolean.class, true)) {
90+
return isRestarterInitialized() || isRemoteRestartEnabled(environment);
91+
}
92+
return false;
8193
}
8294

8395
private boolean isRestarterInitialized() {

spring-boot-project/spring-boot-devtools/src/main/resources/META-INF/additional-spring-configuration-metadata.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"reason": "Remote debug is no longer supported.",
2020
"level": "error"
2121
}
22+
},
23+
{
24+
"name": "spring.devtools.add-properties",
25+
"type": "java.lang.Boolean",
26+
"description": "Whether to enable devtool property defaults.",
27+
"defaultValue": true
2228
}
2329
]
24-
}
30+
}

spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc

+10
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,16 @@ For example, Thymeleaf offers the `spring.thymeleaf.cache` property. Rather than
783783
to set these properties manually, the `spring-boot-devtools` module automatically applies
784784
sensible development-time configuration.
785785

786+
Because you need more information about web requests while developing Spring MVC and
787+
Spring WebFlux applications, developer tools will enable `DEBUG` logging for the `web`
788+
logging group. This will give you information about the incoming request, which handler is
789+
processing it, the response outcome, etc. If you wish to log all request details
790+
(including potentially sensitive information), you can turn on the
791+
`spring.http.log-request-details` configuration property.
792+
793+
NOTE: If you don't want property defaults to be applied you can set
794+
`spring.devtools.add-properties` to `false` in your `application.properties`.
795+
786796
TIP: For a complete list of the properties that are applied by the devtools, see
787797
{sc-spring-boot-devtools}/env/DevToolsPropertyDefaultsPostProcessor.{sc-ext}[DevToolsPropertyDefaultsPostProcessor].
788798

0 commit comments

Comments
 (0)