Skip to content

Logback Access integration with Reactor Netty HTTP server

License

Notifications You must be signed in to change notification settings

dmitrysulman/logback-access-reactor-netty

Repository files navigation

Logback Access for Reactor Netty

Maven Central Version javadoc Build CodeQL codecov

A Java/Kotlin library that integrates Logback Access with Reactor Netty HTTP server, providing comprehensive access logging capabilities.

Overview

Reactor Netty HTTP Server is a non-blocking, asynchronous server built on the Netty networking framework and used as the default runtime for handling HTTP requests in Spring WebFlux. It enables reactive, event-driven processing of web requests, making it well-suited for scalable and high-throughput applications. In Spring Boot, it's automatically configured when building reactive applications with the spring-boot-starter-webflux dependency.

Logback Access is a module of the Logback logging framework that provides HTTP access logging capabilities, similar to those in servlet containers like Tomcat or Jetty. It allows logging of incoming HTTP requests and responses using customizable patterns and supports easy configuration through an XML file.

Logback Access for Reactor Netty library serves as a bridge between the Reactor Netty HTTP logging mechanism and the Logback Access library. It enables detailed HTTP access logging with configurable formats, filters, and appenders through Logback Access configuration.

Features

  • XML-based configuration support
  • Comprehensive HTTP request/response logging
  • Lazy-loaded access event properties for optimal performance
  • Support for headers, cookies, and request parameters logging
  • Configurable through system properties or external configuration files
  • Debug mode for troubleshooting

Dependencies

  • Java 17+
  • Kotlin Standard Library 2.1.21
  • Reactor Netty HTTP Server 1.2.6
  • Logback-access 2.0.6
  • SLF4J 2.0.17

Usage

Adding dependency

Maven

<dependency>
    <groupId>io.github.dmitrysulman</groupId>
    <artifactId>logback-access-reactor-netty</artifactId>
    <version>1.0.4</version>
</dependency>

Gradle

implementation("io.github.dmitrysulman:logback-access-reactor-netty:1.0.4")

Basic Setup

Java

ReactorNettyAccessLogFactory factory = new ReactorNettyAccessLogFactory();
HttpServer.create()
          .accessLog(true, factory)
          .bindNow()
          .onDispose()
          .block();

Kotlin

val factory = ReactorNettyAccessLogFactory()
HttpServer.create()
          .enableLogbackAccess(factory)
          .bindNow()
          .onDispose()
          .block()

Configuration

The library can be configured in several ways:

  1. Default configuration uses logback-access.xml file on the classpath.
  2. System property. Set -Dlogback.access.reactor.netty.config property to specify configuration file location.
  3. Programmatic configuration. Provide configuration file filename or URL of the resource directly:
// Using specific configuration file by the filename
var factory = new ReactorNettyAccessLogFactory("/path/to/logback-access.xml");

// Using specific configuration file as a classpath resource
var factory = new ReactorNettyAccessLogFactory(
        this.getClass().getClassLoader().getResource("custom-logback-access.xml")
);

Spring Boot configuration

Java

@Configuration
public class NettyAccessLogConfiguration {
    @Bean
    public NettyServerCustomizer accessLogNettyServerCustomizer() {
        return (server) ->
                server.accessLog(true, new ReactorNettyAccessLogFactory("path/to/your/logback-access.xml"));
    }
}

Kotlin

@Configuration
class NettyAccessLogConfiguration {
    @Bean
    fun accessLogNettyServerCustomizer() = 
        NettyServerCustomizer { server ->
            server.enableLogbackAccess(ReactorNettyAccessLogFactory("path/to/your/logback-access.xml"))
        }
}

See enableLogbackAccess() extension function documentation.

Documentation

Author

Dmitry Sulman

See Also