Merge pull request #43434 from mpalourdio
* pr/43434: Polish "Add property to specify the management access log prefix" Add property to specify the management access log prefix Closes gh-43434
This commit is contained in:
commit
269c7612e0
|
|
@ -57,6 +57,8 @@ public class ManagementServerProperties {
|
|||
@NestedConfigurationProperty
|
||||
private Ssl ssl;
|
||||
|
||||
private final Accesslog accesslog = new Accesslog();
|
||||
|
||||
/**
|
||||
* Returns the management port or {@code null} if the
|
||||
* {@link ServerProperties#getPort() server port} should be used.
|
||||
|
|
@ -117,4 +119,25 @@ public class ManagementServerProperties {
|
|||
return candidate;
|
||||
}
|
||||
|
||||
public Accesslog getAccesslog() {
|
||||
return this.accesslog;
|
||||
}
|
||||
|
||||
public static class Accesslog {
|
||||
|
||||
/**
|
||||
* Management log file name prefix.
|
||||
*/
|
||||
private String prefix = "management_";
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -47,6 +47,7 @@ import org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFact
|
|||
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryCustomizer;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.TomcatServletWebServerFactoryCustomizer;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.UndertowServletWebServerFactoryCustomizer;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||
|
|
@ -73,6 +74,7 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
|
||||
@ConditionalOnWebApplication(type = Type.SERVLET)
|
||||
@EnableConfigurationProperties(ManagementServerProperties.class)
|
||||
class ServletManagementChildContextConfiguration {
|
||||
|
||||
@Bean
|
||||
|
|
@ -83,20 +85,20 @@ class ServletManagementChildContextConfiguration {
|
|||
|
||||
@Bean
|
||||
@ConditionalOnClass(name = "io.undertow.Undertow")
|
||||
UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer() {
|
||||
return new UndertowAccessLogCustomizer();
|
||||
UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer(ManagementServerProperties properties) {
|
||||
return new UndertowAccessLogCustomizer(properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(name = "org.apache.catalina.valves.AccessLogValve")
|
||||
TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer() {
|
||||
return new TomcatAccessLogCustomizer();
|
||||
TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer(ManagementServerProperties properties) {
|
||||
return new TomcatAccessLogCustomizer(properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(name = "org.eclipse.jetty.server.Server")
|
||||
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer() {
|
||||
return new JettyAccessLogCustomizer();
|
||||
JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) {
|
||||
return new JettyAccessLogCustomizer(properties);
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
|
@ -145,14 +147,18 @@ class ServletManagementChildContextConfiguration {
|
|||
|
||||
abstract static class AccessLogCustomizer implements Ordered {
|
||||
|
||||
private static final String MANAGEMENT_PREFIX = "management_";
|
||||
private final ManagementServerProperties properties;
|
||||
|
||||
AccessLogCustomizer(ManagementServerProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
protected String customizePrefix(String prefix) {
|
||||
prefix = (prefix != null) ? prefix : "";
|
||||
if (prefix.startsWith(MANAGEMENT_PREFIX)) {
|
||||
if (prefix.startsWith(this.properties.getAccesslog().getPrefix())) {
|
||||
return prefix;
|
||||
}
|
||||
return MANAGEMENT_PREFIX + prefix;
|
||||
return this.properties.getAccesslog().getPrefix() + prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -165,6 +171,10 @@ class ServletManagementChildContextConfiguration {
|
|||
static class TomcatAccessLogCustomizer extends AccessLogCustomizer
|
||||
implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
|
||||
|
||||
TomcatAccessLogCustomizer(ManagementServerProperties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(TomcatServletWebServerFactory factory) {
|
||||
AccessLogValve accessLogValve = findAccessLogValve(factory);
|
||||
|
|
@ -188,6 +198,10 @@ class ServletManagementChildContextConfiguration {
|
|||
static class UndertowAccessLogCustomizer extends AccessLogCustomizer
|
||||
implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
|
||||
|
||||
UndertowAccessLogCustomizer(ManagementServerProperties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(UndertowServletWebServerFactory factory) {
|
||||
factory.setAccessLogPrefix(customizePrefix(factory.getAccessLogPrefix()));
|
||||
|
|
@ -198,6 +212,10 @@ class ServletManagementChildContextConfiguration {
|
|||
static class JettyAccessLogCustomizer extends AccessLogCustomizer
|
||||
implements WebServerFactoryCustomizer<JettyServletWebServerFactory> {
|
||||
|
||||
JettyAccessLogCustomizer(ManagementServerProperties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(JettyServletWebServerFactory factory) {
|
||||
factory.addServerCustomizers(this::customizeServer);
|
||||
|
|
|
|||
|
|
@ -68,4 +68,10 @@ class ManagementServerPropertiesTests {
|
|||
assertThat(properties.getBasePath()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessLogsArePrefixedByDefault() {
|
||||
ManagementServerProperties properties = new ManagementServerProperties();
|
||||
assertThat(properties.getAccesslog().getPrefix()).isEqualTo("management_");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue