springspring-bootkotlinnettyreactor-netty

how to exclude request api url in spring netty access log


I currently have netty's access-log running in the following way.

System.setProperty("reactor.netty.http.server.accessLogEnabled", "true")

However, the current Spring Actuator's health log is loaded too frequently in the log storage file, so I would like to exclude URL calls to /health from the log record. Is there a way?


Solution

  • You can use a filter for access log.

    @Component
    public class MyNettyWebServerCustomizer
            implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
        @Override
        public void customize(NettyReactiveWebServerFactory factory) {
            factory.addServerCustomizers(httpServer ->
                httpServer.accessLog(true, AccessLogFactory.createFilter(p ->
                        !String.valueOf(p.uri()).startsWith("/health/"))));
        }
    }
    

    More info you can find here