Skip to content

Commit 3e42a5e

Browse files
committed
feat: Add ability to disable access log prefix for management logs
1 parent 86b0c76 commit 3e42a5e

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties.java

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public class ManagementServerProperties {
5454
*/
5555
private String basePath = "";
5656

57+
/**
58+
* Enable management access logs to be prefixed with management_
59+
* management.server.accesslog.prefix.
60+
*/
61+
private boolean accesslogPrefix = true;
62+
5763
@NestedConfigurationProperty
5864
private Ssl ssl;
5965

@@ -117,4 +123,12 @@ private String cleanBasePath(String basePath) {
117123
return candidate;
118124
}
119125

126+
public boolean getPrefixAccessLogs() {
127+
return this.accesslogPrefix;
128+
}
129+
130+
public void setAccesslogPrefix(boolean accesslogPrefix) {
131+
this.accesslogPrefix = accesslogPrefix;
132+
}
133+
120134
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer() {
8989

9090
@Bean
9191
@ConditionalOnClass(name = "org.apache.catalina.valves.AccessLogValve")
92-
TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer() {
93-
return new TomcatAccessLogCustomizer();
92+
TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer(
93+
ManagementServerProperties managementServerProperties) {
94+
return new TomcatAccessLogCustomizer(managementServerProperties);
9495
}
9596

9697
@Bean
@@ -165,13 +166,22 @@ public int getOrder() {
165166
static class TomcatAccessLogCustomizer extends AccessLogCustomizer
166167
implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
167168

169+
private final ManagementServerProperties managementServerProperties;
170+
171+
TomcatAccessLogCustomizer(ManagementServerProperties managementServerProperties) {
172+
this.managementServerProperties = managementServerProperties;
173+
}
174+
168175
@Override
169176
public void customize(TomcatServletWebServerFactory factory) {
170177
AccessLogValve accessLogValve = findAccessLogValve(factory);
171178
if (accessLogValve == null) {
172179
return;
173180
}
174-
accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix()));
181+
182+
if (this.managementServerProperties.getPrefixAccessLogs()) {
183+
accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix()));
184+
}
175185
}
176186

177187
private AccessLogValve findAccessLogValve(TomcatServletWebServerFactory factory) {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerPropertiesTests.java

+7
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ void slashOfBasePathIsDefaultValue() {
6868
assertThat(properties.getBasePath()).isEmpty();
6969
}
7070

71+
@Test
72+
void accessLogsArePrefixedByDefault() {
73+
ManagementServerProperties properties = new ManagementServerProperties();
74+
properties.setAccesslogPrefix(true);
75+
assertThat(properties.getPrefixAccessLogs()).isTrue();
76+
}
77+
7178
}

0 commit comments

Comments
 (0)