Skip to content

Commit 84e7219

Browse files
committed
Remove automatic devtools web debug logging
Rework `DevToolsPropertyDefaultsPostProcessor` so that web logging no longer defaults to `DEBUG`. The post processor now logs an info hint to suggest the user configure the logging themselves. Closes gh-14575
1 parent 6e00d13 commit 84e7219

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.core.env.ConfigurableEnvironment;
3232
import org.springframework.core.env.Environment;
3333
import org.springframework.core.env.MapPropertySource;
34+
import org.springframework.util.ClassUtils;
3435

3536
/**
3637
* {@link EnvironmentPostProcessor} to add properties that make sense when working at
@@ -49,6 +50,12 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
4950

5051
private static final String ENABLED = "spring.devtools.add-properties";
5152

53+
private static final String WEB_LOGGING = "logging.level.web";
54+
55+
private static final String[] WEB_ENVIRONMENT_CLASSES = {
56+
"org.springframework.web.context.ConfigurableWebEnvironment",
57+
"org.springframework.boot.web.reactive.context.ConfigurableReactiveWebEnvironment" };
58+
5259
private static final Map<String, Object> PROPERTIES;
5360

5461
static {
@@ -66,18 +73,24 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro
6673
properties.put("server.error.include-stacktrace", "ALWAYS");
6774
properties.put("server.servlet.jsp.init-parameters.development", "true");
6875
properties.put("spring.reactor.stacktrace-mode.enabled", "true");
69-
properties.put("logging.level.web", "debug");
7076
PROPERTIES = Collections.unmodifiableMap(properties);
7177
}
7278

7379
@Override
7480
public void postProcessEnvironment(ConfigurableEnvironment environment,
7581
SpringApplication application) {
76-
if (isLocalApplication(environment) && canAddProperties(environment)) {
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));
82+
if (isLocalApplication(environment)) {
83+
if (canAddProperties(environment)) {
84+
logger.info("Devtools property defaults active! Set '" + ENABLED
85+
+ "' to 'false' to disable");
86+
environment.getPropertySources()
87+
.addLast(new MapPropertySource("devtools", PROPERTIES));
88+
}
89+
if (isWebApplication(environment)
90+
&& !environment.containsProperty(WEB_LOGGING)) {
91+
logger.info("For additional web related logging consider "
92+
+ "setting the '" + WEB_LOGGING + "' property to 'DEBUG'");
93+
}
8194
}
8295
}
8396

@@ -106,4 +119,15 @@ private boolean isRemoteRestartEnabled(Environment environment) {
106119
return environment.containsProperty("spring.devtools.remote.secret");
107120
}
108121

122+
private boolean isWebApplication(Environment environment) {
123+
for (String candidate : WEB_ENVIRONMENT_CLASSES) {
124+
Class<?> environmentClass = ClassUtils.resolveClassName(candidate,
125+
environment.getClass().getClassLoader());
126+
if (environmentClass != null && environmentClass.isInstance(environment)) {
127+
return true;
128+
}
129+
}
130+
return false;
131+
}
132+
109133
}

0 commit comments

Comments
 (0)