Spring Boot
application.yml
logging configuration
rolling file appender
logback

How to configure rolling file appender within Spring Boot's application.yml

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Spring Boot can configure basic file logging and log rotation directly from application.yml when you are using Logback, which is the default logging system in a standard Spring Boot application. That is enough for many applications, but it is important to know where the line is: simple rolling settings belong in application.yml, while fully custom appenders usually belong in logback-spring.xml.

Use Boot's built-in rolling policy properties

If you want to log to a file and rotate it by size and history, Spring Boot exposes Logback rolling policy settings under the logging.logback.rollingpolicy prefix.

yaml
1logging:
2  file:
3    name: logs/application.log
4  level:
5    root: INFO
6    com.example: DEBUG
7  logback:
8    rollingpolicy:
9      file-name-pattern: logs/application-%d{yyyy-MM-dd}.%i.log.gz
10      max-file-size: 10MB
11      max-history: 14
12      total-size-cap: 1GB
13      clean-history-on-start: false

This gives you:

  • a current log file at logs/application.log
  • archived files matching the configured pattern
  • size-based rollover
  • retention rules for history and total archive size

For many services, that is enough without any XML configuration.

What this configuration actually does

Boot wires the logging system before most of the application starts. When Logback is on the classpath, these properties are translated into the underlying rolling file configuration.

The key pieces are:

  • 'logging.file.name to enable file logging'
  • 'file-name-pattern to define archive filenames'
  • 'max-file-size to trigger size-based rollover'
  • 'max-history to limit retention'
  • 'total-size-cap to keep archives from growing forever'

This is the simplest way to get controlled file rotation in a Boot application.

When application.yml is not enough

If you need advanced Logback features such as:

  • multiple appenders with different patterns
  • async appenders
  • per-package routing to different files
  • custom encoders or filters

then move the logging configuration into logback-spring.xml. application.yml is good for common rolling settings, but it is not a full replacement for native Logback configuration.

A minimal custom Logback file might start like this:

xml
1<configuration>
2    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
3    <property name="LOG_FILE" value="logs/application.log"/>
4</configuration>

Use that route only when the built-in properties stop being expressive enough.

Keep the setup environment-friendly

Avoid hard-coding paths that work only on one machine. It is often better to externalize the log path:

yaml
logging:
  file:
    name: ${APP_LOG_FILE:logs/application.log}

That allows different environments to override the location without changing the packaged application.

Also make sure the target directory is writable by the running process. A correct configuration still fails if the container or service account cannot create log files.

If you are packaging the app into a container, it is often worth deciding explicitly whether logs should go to rotating files at all or whether they should go to standard output and be rotated by the platform instead. File rolling is useful, but container logging strategy should be intentional.

Common Pitfalls

One pitfall is trying to define a fully custom RollingFileAppender purely in application.yml. Spring Boot's logging properties support common rolling options, but not every Logback feature.

Another issue is forgetting to set logging.file.name or an equivalent file target. Without a file target, rotation settings alone do not create a rolling file log.

It is also easy to mix application.yml settings with a custom logback-spring.xml and then wonder which one wins. Once you supply a custom Logback configuration file, that file becomes the main source of truth for logging behavior.

Finally, watch file permissions and disk paths in containers. Logging misconfiguration often looks like a framework problem when it is really an environment problem.

Summary

  • Spring Boot can configure common Logback file rotation directly in application.yml.
  • Use logging.logback.rollingpolicy.* for standard size and retention settings.
  • Set logging.file.name so Boot knows where the active log file should live.
  • Move to logback-spring.xml when you need advanced custom appenders or routing.
  • Check file paths and permissions before blaming the logging framework.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.