Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Spring Boot uses Logback by default when you use a Boot starter, so most projects can change log levels without adding a logging dependency. Use application.properties or YAML for simple level changes; choose logback-spring.xml when you need appenders, custom formats, rotation, or logging that varies by Spring profile.

How Spring Boot and Logback fit together

Spring Boot uses Commons Logging internally and keeps the concrete logging backend replaceable. With a Boot starter, Logback is the default backend. Boot also routes logging from common facades—including Java Util Logging, Commons Logging, Log4J, and SLF4J—so libraries using different APIs can work within the same application.

The examples below use Spring Boot’s documented configuration names and behavior. Check the reference for the Boot line you run: the stable versions listed in the 2026 reference index were 4.1.1, 4.0.8, 3.5.16, 3.4.13, and 3.3.13; 4.2.0-M1 was development-only at that time. Properties can vary between Boot lines.

Choose the simplest configuration that meets your needs

Change a logging level in application configuration

For a level change, use logging.level.<logger-name> in application.properties or YAML. For example, to set Spring’s web package to DEBUG in properties:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
logging.level.org.springframework.web=DEBUG

Use the logger’s fully qualified package or class name. This Boot property is usually enough when you only need to adjust verbosity; it avoids maintaining a separate Logback file.

Use native Logback configuration for detailed control

When you need to define appenders, encoders, patterns, filters, or rolling policies, configure Logback directly. Spring Boot supports logback-spring.xml, logback-spring.groovy, logback.xml, and logback.groovy, and recommends the -spring variants when possible.

logback-spring.xml versus logback.xml

Concern logback-spring.xml logback.xml
Spring profile and environment extensions Supports Boot’s <springProfile> and <springProperty> extensions. Does not support those extensions because it is loaded too early.
Initialization timing Loaded through Spring Boot’s logging setup, allowing its extensions to be processed. Loaded before Spring Boot can process its extensions.
Configuration scanning Do not combine Boot’s Spring extensions with Logback scanning; a scan reload can fail on those tags. Ordinary Logback configuration can be used, but Spring extensions are unavailable.
Portability outside Spring Boot Uses Boot-specific extensions, so it is not a plain Logback configuration in environments without Boot. Uses standard Logback configuration and is the more portable choice when no Spring-aware tags are needed.
Appenders and rotation Can define native Logback appenders and policies, with Spring extensions available as needed. Can define native Logback appenders and policies, but without Boot’s Spring extensions.

If you need Boot-aware configuration, name the file logback-spring.xml. You can instead set logging.config to identify a configuration file. Spring Boot explains the timing limitation: “Because the standard logback.xml configuration file is loaded too early, you cannot use extensions in it.”

Configure logs by Spring profile or environment property

Condition configuration with springProfile

In logback-spring.xml, <springProfile> includes or excludes Logback configuration according to the active Spring profile. It accepts a single profile, alternatives, negation, and expressions. For example, the documented expression forms include staging, dev | staging, !production, and production & (eu-central | eu-west).

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Place the Logback configuration that should apply only under a condition inside the corresponding <springProfile> element. Use profile names and expressions that match the profiles your application activates.

Expose a Spring property with springProperty

<springProperty> makes a value from Spring’s Environment available in Logback configuration. It supports scope and defaultValue. Use kebab case for the source property name, such as my.property-name.

These tags are Spring Boot extensions, not general Logback tags. If configuration scanning attempts to reload a file containing them, Boot documents errors such as no applicable action for [springProperty] and no applicable action for [springProfile]. Do not enable Logback scanning for a configuration that uses these extensions.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Write logs to a file and control rotation

Enable file output with Boot properties

Spring Boot’s default logging configuration writes to the console and enables ERROR, WARN, and INFO. To also write to a file, set logging.file.name to a file name or logging.file.path to a directory. If both are set, logging.file.name takes precedence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Adjust the rolling policy

Spring Boot documents a default file-rotation threshold of 10 MB and a default maximum history of seven archived files. The available rolling policy properties include:

  • logging.logback.rollingpolicy.file-name-pattern — pattern used for archived file names.
  • logging.logback.rollingpolicy.clean-history-on-start — whether archive history is cleaned when the application starts.
  • logging.logback.rollingpolicy.max-file-size — maximum size for an individual log file before rollover.
  • logging.logback.rollingpolicy.total-size-cap — cap for the combined size of archived logs.
  • logging.logback.rollingpolicy.max-history — maximum number of archive periods to retain.

Use Boot’s rolling policy properties when its built-in file logging is sufficient. If you need a different appender arrangement or policy design, define it in native Logback configuration instead.

Account for logging startup timing

Logging initializes before the Spring ApplicationContext exists. Consequently, @PropertySources declared in a @Configuration class cannot supply values for initial logging setup: that class is processed too late. Make values needed at startup available through external configuration, the logging.config property, or system properties.

Understand the default output and level names

Spring Boot’s sample console format includes a timestamp, level, process ID, separator, optional application name and group, thread name, logger name, and message. Logback does not define a FATAL level; Spring Boot maps FATAL to ERROR.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.