diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties.java index e476398f5415..fcb2a06c8d7c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties.java @@ -54,6 +54,12 @@ public class ManagementServerProperties { */ private String basePath = ""; + /** + * Enable management access logs to be prefixed with management_ + * management.server.accesslog.prefix. + */ + private boolean accesslogPrefix = true; + @NestedConfigurationProperty private Ssl ssl; @@ -117,4 +123,12 @@ private String cleanBasePath(String basePath) { return candidate; } + public boolean getPrefixAccessLogs() { + return this.accesslogPrefix; + } + + public void setAccesslogPrefix(boolean accesslogPrefix) { + this.accesslogPrefix = accesslogPrefix; + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java index 71beda39b6ba..f7b0b5159b77 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java @@ -89,8 +89,9 @@ UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer() { @Bean @ConditionalOnClass(name = "org.apache.catalina.valves.AccessLogValve") - TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer() { - return new TomcatAccessLogCustomizer(); + TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer( + ManagementServerProperties managementServerProperties) { + return new TomcatAccessLogCustomizer(managementServerProperties); } @Bean @@ -165,13 +166,22 @@ public int getOrder() { static class TomcatAccessLogCustomizer extends AccessLogCustomizer implements WebServerFactoryCustomizer { + private final ManagementServerProperties managementServerProperties; + + TomcatAccessLogCustomizer(ManagementServerProperties managementServerProperties) { + this.managementServerProperties = managementServerProperties; + } + @Override public void customize(TomcatServletWebServerFactory factory) { AccessLogValve accessLogValve = findAccessLogValve(factory); if (accessLogValve == null) { return; } - accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix())); + + if (this.managementServerProperties.getPrefixAccessLogs()) { + accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix())); + } } private AccessLogValve findAccessLogValve(TomcatServletWebServerFactory factory) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerPropertiesTests.java index 8ab33edfe81b..88452aa250a3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerPropertiesTests.java @@ -68,4 +68,11 @@ void slashOfBasePathIsDefaultValue() { assertThat(properties.getBasePath()).isEmpty(); } + @Test + void accessLogsArePrefixedByDefault() { + ManagementServerProperties properties = new ManagementServerProperties(); + properties.setAccesslogPrefix(true); + assertThat(properties.getPrefixAccessLogs()).isTrue(); + } + }