Skip to content

Configuration

This page describes all available configuration options for logback-access-spring-boot-starter.

Application Properties

Configure the starter using Spring Boot properties in application.yml or application.properties:

yaml
logback:
  access:
    enabled: true
    # config-location: classpath:custom-access.xml  # Supports classpath: and file: prefixes
    local-port-strategy: server
    tomcat:
      # request-attributes-enabled: true  # Auto-detected from RemoteIpValve
    tee-filter:
      enabled: false
      # include-hosts: localhost,example.com
      # exclude-hosts: internal.example.com
      # max-payload-size: 65536
      # allowed-content-types:
      #   - "text/*"
      #   - "application/json"
    filter:
      # include-url-patterns:
      #   - /api/.*
      exclude-url-patterns:
        - /actuator/.*
        - /health

Property Reference

PropertyDefaultDescription
logback.access.enabledtrueEnable or disable access logging
logback.access.config-locationAuto-detectedPath to logback-access configuration file. Supports classpath: and file: URL prefixes
logback.access.local-port-strategyserverPort resolution strategy: server or local
logback.access.tomcat.request-attributes-enabledAuto-detectedEnable Tomcat request attributes. Auto-detected from RemoteIpValve when not set
logback.access.tee-filter.enabledfalseEnable request/response body capture
logback.access.tee-filter.include-hostsnull (all hosts)Comma-separated list of hosts to include
logback.access.tee-filter.exclude-hostsnull (none)Comma-separated list of hosts to exclude
logback.access.tee-filter.max-payload-size65536Maximum payload size (bytes) to log before suppression
logback.access.tee-filter.allowed-content-typesnullContent-Type patterns allowed for body capture (override mode)
logback.access.filter.include-url-patternsnullURL patterns to include (regex)
logback.access.filter.exclude-url-patternsnullURL patterns to exclude (regex)

Configuration File Resolution

When logback.access.config-location is set, that path is used directly (no fallback). If the specified file does not exist, the application will fail to start with an error.

When not set, the starter searches in the following order:

  1. classpath:logback-access-test.xml (for testing)
  2. classpath:logback-access.xml
  3. classpath:logback-access-test-spring.xml (for testing with Spring features)
  4. classpath:logback-access-spring.xml
  5. Built-in fallback configuration

XML Configuration

Basic Structure

xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- Appenders define where logs go -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%h %l %u [%t] "%r" %s %b</pattern>
        </encoder>
    </appender>

    <!-- Reference appenders to activate them -->
    <appender-ref ref="console"/>
</configuration>

Using Spring Properties

Inject Spring properties into your configuration:

xml
<configuration>
    <springProperty name="appName" source="spring.application.name"
                    defaultValue="app" scope="context"/>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>[${appName}] %h %l %u [%t] "%r" %s %b</pattern>
        </encoder>
    </appender>
    <appender-ref ref="console"/>
</configuration>

Default Scope

The default scope for <springProperty> is LOCAL. Properties with LOCAL scope are only available during XML configuration processing for variable substitution (e.g., ${varName}). To access properties programmatically via context.getProperty(), set scope="context".

Using Spring Profiles

Configure different appenders for different environments:

xml
<configuration>
    <springProfile name="dev">
        <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%h %l %u [%t] "%r" %s %b %D</pattern>
            </encoder>
        </appender>
        <appender-ref ref="console"/>
    </springProfile>

    <springProfile name="prod">
        <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>logs/access.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>logs/access.%d{yyyy-MM-dd}.log</fileNamePattern>
                <maxHistory>30</maxHistory>
            </rollingPolicy>
            <encoder>
                <pattern>%h %l %u [%t] "%r" %s %b</pattern>
            </encoder>
        </appender>
        <appender-ref ref="file"/>
    </springProfile>
</configuration>

Profile Expressions

Spring profile expressions support negation and multiple profiles:

xml
<!-- Active when NOT in production -->
<springProfile name="!prod">
    ...
</springProfile>

<!-- Active in dev OR staging -->
<springProfile name="dev, staging">
    ...
</springProfile>

File Appender

Write access logs to a file:

xml
<appender name="file" class="ch.qos.logback.core.FileAppender">
    <file>logs/access.log</file>
    <encoder>
        <pattern>%h %l %u [%t] "%r" %s %b</pattern>
    </encoder>
</appender>

Rolling File Appender

Rotate logs based on time or size:

xml
<appender name="rolling" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/access.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
        <fileNamePattern>logs/access.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
        <maxFileSize>100MB</maxFileSize>
        <maxHistory>30</maxHistory>
        <totalSizeCap>3GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
        <pattern>%h %l %u [%t] "%r" %s %b</pattern>
    </encoder>
</appender>

Disabling Access Logging

Set the property to disable access logging:

yaml
logback:
  access:
    enabled: false

Or use a Spring profile:

yaml
spring:
  profiles:
    active: test

---
spring:
  config:
    activate:
      on-profile: test

logback:
  access:
    enabled: false

See Also

Released under the Apache 2.0 License.