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
This commit is contained in:
parent
c4caf2705a
commit
cef635d86c
|
@ -20,7 +20,10 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.devtools.logger.DevToolsLogFactory;
|
||||||
import org.springframework.boot.devtools.restart.Restarter;
|
import org.springframework.boot.devtools.restart.Restarter;
|
||||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
|
@ -28,7 +31,6 @@ import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.MapPropertySource;
|
import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.core.env.PropertySource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnvironmentPostProcessor} to add properties that make sense when working at
|
* {@link EnvironmentPostProcessor} to add properties that make sense when working at
|
||||||
|
@ -42,33 +44,40 @@ import org.springframework.core.env.PropertySource;
|
||||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||||
public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
|
public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
|
||||||
|
|
||||||
|
private static final Log logger = DevToolsLogFactory
|
||||||
|
.getLog(DevToolsPropertyDefaultsPostProcessor.class);
|
||||||
|
|
||||||
|
private static final String ENABLED = "spring.devtools.add-properties";
|
||||||
|
|
||||||
private static final Map<String, Object> PROPERTIES;
|
private static final Map<String, Object> PROPERTIES;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Map<String, Object> devToolsProperties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
devToolsProperties.put("spring.thymeleaf.cache", "false");
|
properties.put("spring.thymeleaf.cache", "false");
|
||||||
devToolsProperties.put("spring.freemarker.cache", "false");
|
properties.put("spring.freemarker.cache", "false");
|
||||||
devToolsProperties.put("spring.groovy.template.cache", "false");
|
properties.put("spring.groovy.template.cache", "false");
|
||||||
devToolsProperties.put("spring.mustache.cache", "false");
|
properties.put("spring.mustache.cache", "false");
|
||||||
devToolsProperties.put("server.servlet.session.persistent", "true");
|
properties.put("server.servlet.session.persistent", "true");
|
||||||
devToolsProperties.put("spring.h2.console.enabled", "true");
|
properties.put("spring.h2.console.enabled", "true");
|
||||||
devToolsProperties.put("spring.resources.cache.period", "0");
|
properties.put("spring.resources.cache.period", "0");
|
||||||
devToolsProperties.put("spring.resources.chain.cache", "false");
|
properties.put("spring.resources.chain.cache", "false");
|
||||||
devToolsProperties.put("spring.template.provider.cache", "false");
|
properties.put("spring.template.provider.cache", "false");
|
||||||
devToolsProperties.put("spring.mvc.log-resolved-exception", "true");
|
properties.put("spring.mvc.log-resolved-exception", "true");
|
||||||
devToolsProperties.put("server.error.include-stacktrace", "ALWAYS");
|
properties.put("server.error.include-stacktrace", "ALWAYS");
|
||||||
devToolsProperties.put("server.servlet.jsp.init-parameters.development", "true");
|
properties.put("server.servlet.jsp.init-parameters.development", "true");
|
||||||
devToolsProperties.put("spring.reactor.stacktrace-mode.enabled", "true");
|
properties.put("spring.reactor.stacktrace-mode.enabled", "true");
|
||||||
PROPERTIES = Collections.unmodifiableMap(devToolsProperties);
|
properties.put("logging.level.web", "debug");
|
||||||
|
PROPERTIES = Collections.unmodifiableMap(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||||
SpringApplication application) {
|
SpringApplication application) {
|
||||||
if (isLocalApplication(environment) && canAddProperties(environment)) {
|
if (isLocalApplication(environment) && canAddProperties(environment)) {
|
||||||
PropertySource<?> propertySource = new MapPropertySource("refresh",
|
logger.info("Devtools property and logging defaults active! Set '" + ENABLED
|
||||||
PROPERTIES);
|
+ "' to 'false' to disable");
|
||||||
environment.getPropertySources().addLast(propertySource);
|
environment.getPropertySources()
|
||||||
|
.addLast(new MapPropertySource("devtools", PROPERTIES));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +86,10 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canAddProperties(Environment environment) {
|
private boolean canAddProperties(Environment environment) {
|
||||||
return isRestarterInitialized() || isRemoteRestartEnabled(environment);
|
if (environment.getProperty(ENABLED, Boolean.class, true)) {
|
||||||
|
return isRestarterInitialized() || isRemoteRestartEnabled(environment);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRestarterInitialized() {
|
private boolean isRestarterInitialized() {
|
||||||
|
|
|
@ -19,6 +19,12 @@
|
||||||
"reason": "Remote debug is no longer supported.",
|
"reason": "Remote debug is no longer supported.",
|
||||||
"level": "error"
|
"level": "error"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.devtools.add-properties",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "Whether to enable devtool property defaults.",
|
||||||
|
"defaultValue": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -783,6 +783,16 @@ For example, Thymeleaf offers the `spring.thymeleaf.cache` property. Rather than
|
||||||
to set these properties manually, the `spring-boot-devtools` module automatically applies
|
to set these properties manually, the `spring-boot-devtools` module automatically applies
|
||||||
sensible development-time configuration.
|
sensible development-time configuration.
|
||||||
|
|
||||||
|
Because you need more information about web requests while developing Spring MVC and
|
||||||
|
Spring WebFlux applications, developer tools will enable `DEBUG` logging for the `web`
|
||||||
|
logging group. This will give you information about the incoming request, which handler is
|
||||||
|
processing it, the response outcome, etc. If you wish to log all request details
|
||||||
|
(including potentially sensitive information), you can turn on the
|
||||||
|
`spring.http.log-request-details` configuration property.
|
||||||
|
|
||||||
|
NOTE: If you don't want property defaults to be applied you can set
|
||||||
|
`spring.devtools.add-properties` to `false` in your `application.properties`.
|
||||||
|
|
||||||
TIP: For a complete list of the properties that are applied by the devtools, see
|
TIP: For a complete list of the properties that are applied by the devtools, see
|
||||||
{sc-spring-boot-devtools}/env/DevToolsPropertyDefaultsPostProcessor.{sc-ext}[DevToolsPropertyDefaultsPostProcessor].
|
{sc-spring-boot-devtools}/env/DevToolsPropertyDefaultsPostProcessor.{sc-ext}[DevToolsPropertyDefaultsPostProcessor].
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue