Use application.yaml for logging settings that Spring Boot exposes as properties—such as logger levels, a log file path, rotation limits and structured-output formats. Use logback-spring.xml for Logback-specific wiring such as appenders, encoders, layouts and profile-based configuration. YAML can control Logback through Spring Boot, but it does not replace Logback’s native configuration language.
What belongs in YAML and what belongs in Logback XML?
| Need | Use | Why |
|---|---|---|
| Set a logger or package level | application.yaml |
Spring Boot exposes logger levels as properties. |
| Choose the log file and configure supported rotation or retention options | application.yaml |
These are properties supported by Spring Boot’s logging system. |
| Select a built-in structured logging format | application.yaml |
Spring Boot provides format selectors for console and file output. |
| Define appenders, encoders, layouts or detailed output wiring | logback-spring.xml |
These are native Logback configuration elements. |
| Use Spring-aware Logback extensions such as profiles or Spring properties | logback-spring.xml, or a Spring-aware file selected with logging.config |
The -spring variant allows Spring Boot to process its Logback extensions. |
Set logger levels and file rotation in application.yaml
Put Boot-supported logging properties under the logging key. For example:
logging:
level:
org.springframework.web: DEBUG
org.hibernate: ERROR
file:
name: myapplication.log
logback:
rollingpolicy:
file-name-pattern: '${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz'
max-file-size: 10MB
max-history: 7
total-size-cap: 1GB
clean-history-on-start: false
The nested shape for logger levels and logging.file.name is shown in the Spring Boot 3.4 logging how-to. The rolling-policy property names are documented in the Spring Boot 4.0 logging reference; that reference states that max-history defaults to 7. These docs cover different Boot lines, so check the reference matching your project version before relying on a property’s availability or behavior.
Configure appenders and encoders in logback-spring.xml
For Logback-native configuration, create src/main/resources/logback-spring.xml. Spring Boot provides reusable Logback resources, including default settings and console and file appenders. A basic console configuration can include the defaults and console appender, then attach the appender to the root logger:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
The included resources and their supported names are listed in the Spring Boot logging how-to. Use this XML layer when you need to define how logging is assembled, rather than only setting values Boot already exposes.
Why use logback-spring.xml instead of logback.xml?
Spring Boot says the standard logback.xml is loaded too early for Boot’s Logback extensions. Prefer logback-spring.xml when using features such as <springProfile> or <springProperty>. If the configuration file is not in a default classpath location, set logging.config to identify it. Boot also warns that its extensions cannot be used with Logback configuration scanning. See the Spring Boot logging reference.
Rank #2
Logging initializes before the application context. As a result, settings supplied only through @PropertySources on a configuration class cannot control the initial logging setup. Put early logging settings in a source available to Boot’s logging system, such as application configuration, or configure Logback in the Spring-aware XML file.
Write logs to a file without console output
To make a custom configuration file-only, include Boot’s defaults and file appender, but do not include the console appender. Configure the root logger to reference FILE, and set the file target with logging.file.name in application.yaml:
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →logging:
file:
name: myapplication.log
Conceptually, the XML includes org/springframework/boot/logging/logback/defaults.xml and org/springframework/boot/logging/logback/file-appender.xml, then attaches the FILE appender to the root logger. Boot documents these reusable resources in its logging how-to.
Choose a structured logging format
Spring Boot supports ECS, GELF and Logstash structured formats. Select a format for console output, file output or both in YAML; for example, ECS on both targets:
Rank #4
logging:
structured:
format:
console: ecs
file: ecs
If you maintain custom Logback configuration, use Boot’s StructuredLogEncoder and pass the CONSOLE_LOG_STRUCTURED_FORMAT or FILE_LOG_STRUCTURED_FORMAT system property as documented. See the Spring Boot logging reference for the structured logging options and custom configuration details.
Check version compatibility before copying a configuration
Property names and structured-logging support can differ across Spring Boot releases. The examples above draw on Spring Boot 3.4 and 4.0 documentation; consult the reference for the version used by your application before adopting a setting. The essential division remains practical: use Boot properties for supported logging controls and native Logback XML for the configuration elements those properties do not represent.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

