Skip to content

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:

ArtifactDescription
logback-access-spring-boot-starterAuto-configuration and server integrations (Tomcat, Jetty, Security, TeeFilter)
logback-access-spring-boot-starter-corePublic 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 VERSION with the latest version from Maven Central.

kotlin
implementation("io.github.seijikohara:logback-access-spring-boot-starter:VERSION")
groovy
implementation 'io.github.seijikohara:logback-access-spring-boot-starter:VERSION'
xml
<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
<?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:

VariableDescription
%hRemote host (IP address)
%aRemote IP address
%ALocal IP address
%pLocal port
%lRemote log name (always -)
%uRemote user (from authentication)
%tRequest timestamp
%rRequest line (method, URI, protocol)
%sHTTP status code
%bResponse body size in bytes
%DRequest processing time in milliseconds
%TRequest processing time in seconds
%IThread name
%{xxx}iRequest header xxx
%{xxx}oResponse header xxx
%{xxx}cCookie value xxx
%{xxx}rRequest attribute xxx
%queryStringQuery string (includes ? prefix, e.g., ?name=value)
%requestContentRequest body (requires TeeFilter)
%responseContentResponse 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:

xml
<pattern>%h %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"</pattern>

Verify Installation

  1. Start your Spring Boot application
  2. Make an HTTP request to any endpoint
  3. 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 1234

Next Steps

Released under the Apache 2.0 License.