Skip to content

Commit

Permalink
Polish "Add property to specify the management access log prefix"
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Jan 15, 2025
1 parent 020fd7b commit bcf075b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public Accesslog getAccesslog() {
public static class Accesslog {

/**
* Enable management access logs prefix customization
* management.server.accesslog.prefix.
* Management log file name prefix.
*/
private String prefix = "management_";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -85,22 +85,20 @@ ServletManagementWebServerFactoryCustomizer servletManagementWebServerFactoryCus

@Bean
@ConditionalOnClass(name = "io.undertow.Undertow")
UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer(
ManagementServerProperties managementServerProperties) {
return new UndertowAccessLogCustomizer(managementServerProperties);
UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer(ManagementServerProperties properties) {
return new UndertowAccessLogCustomizer(properties);
}

@Bean
@ConditionalOnClass(name = "org.apache.catalina.valves.AccessLogValve")
TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer(
ManagementServerProperties managementServerProperties) {
return new TomcatAccessLogCustomizer(managementServerProperties);
TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer(ManagementServerProperties properties) {
return new TomcatAccessLogCustomizer(properties);
}

@Bean
@ConditionalOnClass(name = "org.eclipse.jetty.server.Server")
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties managementServerProperties) {
return new JettyAccessLogCustomizer(managementServerProperties);
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) {
return new JettyAccessLogCustomizer(properties);
}

@Configuration(proxyBeanMethods = false)
Expand Down Expand Up @@ -149,18 +147,18 @@ private String getContextPath(ManagementServerProperties managementServerPropert

abstract static class AccessLogCustomizer implements Ordered {

protected final ManagementServerProperties managementServerProperties;
private final ManagementServerProperties properties;

AccessLogCustomizer(ManagementServerProperties managementServerProperties) {
this.managementServerProperties = managementServerProperties;
AccessLogCustomizer(ManagementServerProperties properties) {
this.properties = properties;
}

protected String customizePrefix(String prefix) {
prefix = (prefix != null) ? prefix : "";
if (prefix.startsWith(this.managementServerProperties.getAccesslog().getPrefix())) {
if (prefix.startsWith(this.properties.getAccesslog().getPrefix())) {
return prefix;
}
return this.managementServerProperties.getAccesslog().getPrefix() + prefix;
return this.properties.getAccesslog().getPrefix() + prefix;
}

@Override
Expand All @@ -173,8 +171,8 @@ public int getOrder() {
static class TomcatAccessLogCustomizer extends AccessLogCustomizer
implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

TomcatAccessLogCustomizer(ManagementServerProperties managementServerProperties) {
super(managementServerProperties);
TomcatAccessLogCustomizer(ManagementServerProperties properties) {
super(properties);
}

@Override
Expand All @@ -183,7 +181,6 @@ public void customize(TomcatServletWebServerFactory factory) {
if (accessLogValve == null) {
return;
}

accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix()));
}

Expand All @@ -201,8 +198,8 @@ private AccessLogValve findAccessLogValve(TomcatServletWebServerFactory factory)
static class UndertowAccessLogCustomizer extends AccessLogCustomizer
implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {

UndertowAccessLogCustomizer(ManagementServerProperties managementServerProperties) {
super(managementServerProperties);
UndertowAccessLogCustomizer(ManagementServerProperties properties) {
super(properties);
}

@Override
Expand All @@ -215,8 +212,8 @@ public void customize(UndertowServletWebServerFactory factory) {
static class JettyAccessLogCustomizer extends AccessLogCustomizer
implements WebServerFactoryCustomizer<JettyServletWebServerFactory> {

JettyAccessLogCustomizer(ManagementServerProperties managementServerProperties) {
super(managementServerProperties);
JettyAccessLogCustomizer(ManagementServerProperties properties) {
super(properties);
}

@Override
Expand Down

0 comments on commit bcf075b

Please sign in to comment.