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.
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.
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.nameto enable file logging' - '
file-name-patternto define archive filenames' - '
max-file-sizeto trigger size-based rollover' - '
max-historyto limit retention' - '
total-size-capto 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:
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:
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.nameso Boot knows where the active log file should live. - Move to
logback-spring.xmlwhen you need advanced custom appenders or routing. - Check file paths and permissions before blaming the logging framework.
Related reading
- How to configure slf4j-simple
- How to configure/create a Load Balancer that handles users that need to be on the same server
- how to connect to geographically close datacenter
- How to continue a Docker container which has exited
- How to configure spring-boot to use file based H2 database
- How to configure spring-data-mongodb to use a replica set via properties
- how to control frequency of loss logging messages when using tf.Estimator?
- How to control tensorflow's VLOG?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.