Getting Started
This guide explains how to add HTTP access logging to your Spring Boot application.
Prerequisites
- Java 21 or later
- Spring Boot 4.0 or later
- Tomcat or Jetty embedded server
Module Structure
The library consists of two Maven artifacts:
| Artifact | Description |
|---|---|
logback-access-spring-boot-starter | Auto-configuration and server integrations (Tomcat, Jetty, Security, TeeFilter) |
logback-access-spring-boot-starter-core | Public API classes (transitive dependency — no need to declare separately) |
Most users only need to declare the starter dependency. The core module is automatically included as a transitive dependency.
Installation
Add the dependency to your build file:
Replace
VERSIONwith the latest version from Maven Central.
implementation("io.github.seijikohara:logback-access-spring-boot-starter:VERSION")implementation 'io.github.seijikohara:logback-access-spring-boot-starter:VERSION'<dependency>
<groupId>io.github.seijikohara</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
<version>VERSION</version>
</dependency>Basic Configuration
Create a logback-access.xml file in src/main/resources:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%h %l %u [%t] "%r" %s %b</pattern>
</encoder>
</appender>
<appender-ref ref="console"/>
</configuration>This configuration outputs access logs in the Common Log Format (CLF).
Pattern Variables
The following pattern variables are available:
| Variable | Description |
|---|---|
%h | Remote host (IP address) |
%a | Remote IP address |
%A | Local IP address |
%p | Local port |
%l | Remote log name (always -) |
%u | Remote user (from authentication) |
%t | Request timestamp |
%r | Request line (method, URI, protocol) |
%s | HTTP status code |
%b | Response body size in bytes |
%D | Request processing time in milliseconds |
%T | Request processing time in seconds |
%I | Thread name |
%{xxx}i | Request header xxx |
%{xxx}o | Response header xxx |
%{xxx}c | Cookie value xxx |
%{xxx}r | Request attribute xxx |
%queryString | Query string (includes ? prefix, e.g., ?name=value) |
%requestContent | Request body (requires TeeFilter) |
%responseContent | Response body (requires TeeFilter) |
Alternative Syntax
For header, cookie, and attribute patterns, both %{name}i and %i{name} forms are supported. The examples in this documentation use the %i{name} form.
Combined Log Format
For a more detailed output similar to Apache's Combined Log Format:
<pattern>%h %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"</pattern>Verify Installation
- Start your Spring Boot application
- Make an HTTP request to any endpoint
- Check the console output for access log entries
Example output:
127.0.0.1 - - [01/Jan/2026:12:00:00 +0000] "GET /api/users HTTP/1.1" 200 1234Next Steps
- Configuration Reference - Learn about all configuration options
- Tomcat Integration - Tomcat-specific settings
- Jetty Integration - Jetty-specific settings
- Advanced Topics - TeeFilter, URL filtering, and more