Skip to content

Commit

Permalink
feat: Add ability to disable access log prefix for management logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalourdio committed Dec 7, 2024
1 parent 86b0c76 commit 37d1c1c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -165,13 +166,22 @@ public int getOrder() {
static class TomcatAccessLogCustomizer extends AccessLogCustomizer
implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

private final ManagementServerProperties managementServerProperties;

public 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ void slashOfBasePathIsDefaultValue() {
assertThat(properties.getBasePath()).isEmpty();
}

@Test
void accessLogsArePrefixedByDefault() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.setAccesslogPrefix(true);
assertThat(properties.getPrefixAccessLogs()).isTrue();
}

}

0 comments on commit 37d1c1c

Please sign in to comment.