Reputation: 13
I try to configure a custom access log for the management server of my reactive spring-cloud-gateway application.
For the default server i can do this by using a WebServerFactoryCustomizer like:
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
@Slf4j
@Configuration
public class DefaultServerConfig {
@Bean
public WebServerFactoryCustomizer<NettyReactiveWebServerFactory> defaultServerCustomizer() {
return factory -> factory.addServerCustomizers((httpServer) -> {
log.info("Enable custom AccessLog for default server on bind: {}", httpServer.configuration().bindAddress().get());
return httpServer.accessLog(true, CustomAccessLog::createExtLog);
});
}
}
which works perfectly fine.
For the management server i tried to accomplish the same by using @ManagementContextConfiguration
like:
@Slf4j
@ManagementContextConfiguration
public class ManagementServerConfig {
@Bean
public WebServerFactoryCustomizer<NettyReactiveWebServerFactory> managementServerCustomizer() {
return factory -> factory.addServerCustomizers((httpServer) -> {
log.info("Enable custom AccessLog for management server on bind: {}", httpServer.configuration().bindAddress().get());
return httpServer.accessLog(true, CustomAccessLog::createExtLog);
});
}
}
However this also just configures the primary server, as shown in the logging output:
2025-01-21 14:52:49:281 INFO restartedMain d.n.a.w.c.DefaultServerConfig:? - Enable custom AccessLog for default server on bind: 0.0.0.0/0.0.0.0:8080
2025-01-21 14:52:49:283 INFO restartedMain d.n.a.w.c.ManagementServerConfig:? - Enable custom AccessLog for management server on bind: 0.0.0.0/0.0.0.0:8080
My configuration is as simple as
server.port=8080
management.server.port=9000
Upvotes: 0
Views: 35