java – How to turn on the access log for Spring WebFlux?

java – How to turn on the access log for Spring WebFlux?

This has been implemented in Netty v0.7.9.RELEASE following this issue. According to the instructions posted here you can enable the log so:

  • Run your application with -Dreactor.netty.http.server.accessLogEnabled=true system property


  • Enable INFO logging of reactor.netty.http.server.AccessLog

Note that only CLF is supported for the moment.

Other solutions, available before that feature was implemented, are eg.:

Wire log

As @GreyTeardrop mentioned in the comment, you can set the log level of and reactor.ipc.netty.http.server.HttpServer to DEBUG. This will produce a multi-line dump of each message as a hex + ASCII table. Not exactly pleasant fo production use, but can be useful for debugging.

Spring Actuator HTTP trace

If you have Spring Actuator in your project, is supports tracing of HTTP requests. The trace information is sent to a HttpTraceRepository bean. By default its a InMemoryHttpTraceRepository that holds the last 100 traces.

You can leverage that by implementing your own HttpTraceRepository or a decorator to it that will add logging of the traces. You need to register it as a bean – it will replace the autoconfigured InMemoryHttpTraceRepository.

Note that the HTTP traces only have a limited set of information about the request and response, eg. you dont have access to request/response body or size.

A solution that I ended up implementing looks like this:

public HttpTraceRepository httpTraceRepository() {
    return new AccessLoggingHttpTraceRepositoryDecorator(
            new InMemoryHttpTraceRepository(),
            new HttpTraceLogFormatter()

public class AccessLoggingHttpTraceRepositoryDecorator implements HttpTraceRepository {

    private HttpTraceRepository delegate;
    private Logger logger;
    private HttpTraceLogFormatter formatter;

    public AccessLoggingHttpTraceRepositoryDecorator(HttpTraceRepository delegate, Logger logger, HttpTraceLogFormatter formatter) {
        this.delegate = delegate;
        this.logger = logger;
        this.formatter = formatter;

    public List<HttpTrace> findAll() {
        return delegate.findAll();

    public void add(HttpTrace trace) {
        if (logger.isDebugEnabled()) {
            try {
            } catch (Exception e) {
                logger.error(Failed to log trace  + trace, e);

public class HttpTraceLogFormatter {
    public String format(HttpTrace trace) {
        // TODO implement this according to your preference
        return ...;

With this approach you can get an almost Common Log Format message.

You may need to adjust in your application.yml what is included in the trace object by specifying



Your own access logging WebFilter

Spring Boot Actuator implements tracing with the help of HttpTraceWebFilter. If you dont want to use the Actuators solution, you may take inspiration from the source code of the HttpTraceWebFilter and implement your own WebFilter. Expose it as a Spring bean and it will be automatically registered with Netty.

Support for access logs has been added to the latest version of Reactor Netty.
Just update you Reactor version to <reactor-bom.version>Bismuth-SR11</reactor-bom.version>
Then you just need to enable logging of reactor.netty.http.server.AccessLog into access_log.log using whatever logging framework you are using.

See here for details:

java – How to turn on the access log for Spring WebFlux?

Enable netty access log using Java System Property,


and you can have logging system configured to have a separate access log file.

Below is an example log4j2 configuration.

 <RollingRandomAccessFile name=ACCESS_LOG fileName=access.log
            <PatternLayout pattern=[%t] %d{dd MM yyyy HH:mm:ss,SSS} %-5p %-15c{1} [%X]: %m%n/>
                <SizeBasedTriggeringPolicy size=5 MB/>
            <DefaultRolloverStrategy max=4/>
 <logger name=reactor.netty.http.server.AccessLog level=INFO additivity=false>
            <AppenderRef ref=ACCESS_LOG/>

Leave a Reply

Your email address will not be published. Required fields are marked *