A Java/Kotlin library and Spring Boot Starter that integrates Logback Access with Reactor Netty HTTP server, providing comprehensive access logging capabilities for reactive web applications.
- Overview
- Features
- Usage
- Using as a Spring Boot Starter
- Using as a standalone library
- API documentation
- See also
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 and Spring Cloud Gateway. 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 library that provides HTTP access logging capabilities for 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 XML configuration.
- Spring Boot Starter with auto-configuration
- 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
The Logback Access integration with Reactor Netty can be used in two ways:
- As a Spring Boot Starter for reactive Spring Boot applications based on
spring-boot-starter-webflux
. - As a standalone library for applications using Reactor Netty HTTP Server directly.
The Spring Boot Starter is published on Maven Central. To add the dependency, use the following snippet according to your build system:
implementation("io.github.dmitrysulman:logback-access-reactor-netty-spring-boot-starter:1.1.0")
<dependency>
<groupId>io.github.dmitrysulman</groupId>
<artifactId>logback-access-reactor-netty-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
Default Spring Boot auto-configuration uses the logback-access.xml
file from the current directory or the classpath, with a fallback to the Common Log Format.
Set the logback.access.reactor.netty.config
application property to specify the location of the configuration file. The property value is resolved as a resource, which means you can use prefixes like file:
or classpath:
.
Several application properties can be specified in the application.properties
or application.yaml
file, or passed as command-line arguments:
Name | Description | Default Value |
---|---|---|
logback.access.reactor.netty.enabled |
Enable Logback Access Reactor Netty auto-configuration. | true |
logback.access.reactor.netty.config |
Config file name. | logback-access.xml |
logback.access.reactor.netty.debug |
Enable debug mode. | false |
The <springProfile>
tag allows you to conditionally include or exclude parts of the configuration based on the active Spring profiles. You can use it anywhere within the <configuration>
element. Specify the applicable profile using the name
attribute, which can be either a single profile name (e.g., staging
) or a profile expression. For more details, see the Spring Boot Logback Extensions Profile-specific Configuration reference guide, which describes the same usage. There are several examples:
<springProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>
<springProfile name="dev | staging">
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>
<springProfile name="!production">
<!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>
- Java 17+
- Kotlin Standard Library 2.1.21
- Spring Boot Starter WebFlux 3.4.6+ (should be explicitly provided)
- Logback-access 2.0.6
- SLF4J 2.0.17
The library is published on Maven Central. To add the dependency, use the following snippet according to your build system:
implementation("io.github.dmitrysulman:logback-access-reactor-netty:1.1.0")
<dependency>
<groupId>io.github.dmitrysulman</groupId>
<artifactId>logback-access-reactor-netty</artifactId>
<version>1.1.0</version>
</dependency>
To enable Logback Access integration with Reactor Netty, create a new instance of ReactorNettyAccessLogFactory
and pass it to the HttpServer.accessLog()
method.
ReactorNettyAccessLogFactory factory = new ReactorNettyAccessLogFactory();
HttpServer.create()
.accessLog(true, factory)
.bindNow()
.onDispose()
.block();
For Kotlin, a convenient enableLogbackAccess() extension function is provided to pass the factory instance.
val factory = ReactorNettyAccessLogFactory()
HttpServer.create()
.enableLogbackAccess(factory)
.bindNow()
.onDispose()
.block()
Logback Access can be configured in several ways:
- Default configuration uses the
logback-access.xml
file from the current directory or the classpath, with a fallback to the Common Log Format. - System property. Set
-Dlogback.access.reactor.netty.config
property to specify configuration file location. - Programmatic configuration. Provide configuration file filename or URL of the classpath 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")
);
- Java 17+
- Kotlin Standard Library 2.1.21
- Reactor Netty HTTP Server 1.2.6+ (should be explicitly provided)
- Logback-access 2.0.6
- SLF4J 2.0.17