Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

In a Spring Boot application, what is the difference between logback.xml and logback-spring.xml, and how do application.properties settings such as logging.level.* and logging.file.name interact with them?

logback.xml is a standard Logback file that Logback itself can load very early, before Spring's Environment exists, so it cannot use Spring profiles or properties; logback-spring.xml is loaded by Spring Boot's LoggingSystem after the Environment is ready and supports <springProfile> and <springProperty>. logging.level.* properties are applied on top of whichever file we use, while logging.file.name and logging.file.path only produce a file with Boot's default configuration or a custom file that includes Boot's file appender.

Why this question is asked

Logging configuration in Spring Boot looks simple until two sources disagree: the XML file says one thing, application.properties says another, and the output matches neither. Interviewers ask this question because the answer shows whether we understand the order in which Boot starts up, and that order explains most surprises with logging configuration. In this answer, we will see how Logback configures itself, what Spring Boot adds on top, why the -spring file name matters, how logging.level and logging.file properties interact with a custom file, how to keep Boot's defaults while customising, and where logging.config and Log4j2 fit in.

1How Logback Configures Itself

Logback is a standalone library. The first time any code asks for a logger, Logback initialises itself by looking on the classpath for logback-test.xml and then logback.xml. If it finds neither, it falls back to a basic console configuration. This happens extremely early, as soon as the first class with a static logger is loaded, which in a Spring Boot application is before Spring has read application.properties, activated profiles or created a single bean.

So a plain logback.xml is read by Logback with no knowledge of Spring at all. It can use system properties and environment variables, but not Spring profiles or values from application.yml.

2What Spring Boot Adds

Spring Boot has its own logging abstraction, the LoggingSystem, with an implementation per backend. When the application starts, Boot's logging listener waits until the Environment is prepared, that is, until profiles and properties are known, and then reconfigures Logback. If it finds logback-spring.xml (or a standard logback.xml), it loads that file through its own configurator, which understands two extra tags.

XML
<!-- logback-spring.xml -->
<configuration>
<springProperty name="APP" source="spring.application.name" defaultValue="app"/>
<springProfile name="local">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
</springProfile>
<springProfile name="prod">
<appender name="JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"service":"${APP}"}</customFields>
</encoder>
</appender>
<root level="INFO"><appender-ref ref="JSON"/></root>
</springProfile>
</configuration>
Step throughStartup order
JVMLogbackSpring BootLoggingSystem
first logger requested
self-configure: logback-test.xml, logback.xml or defaults
SpringApplication.run()
Environment prepared: profiles, properties
initialize logging
reset and load logback-spring.xml with spring tags
apply logging.level.* properties

7 messages in order. Play them, or step through them one at a time.

<springProfile> includes its content only when the named profile is active, and <springProperty> copies a value from the Spring Environment into a Logback variable. If we put these tags in a plain logback.xml, Logback reads the file first on its own and does not understand them, and we get errors or configuration that is silently ignored. That is the main reason Boot recommends the -spring suffix: it guarantees that only Boot, with the Environment ready, ever reads the file.

3How logging.level.* Interacts With the File

After loading the configuration file, the LoggingSystem applies every logging.level.<logger> property. So the properties win over levels written in the XML for the same logger.

Java
# application.properties
logging.level.com.shop=DEBUG
logging.level.org.hibernate.SQL=DEBUG
<!-- in logback-spring.xml -->
<logger name="com.shop" level="WARN"/>
// effective level of com.shop at runtime: DEBUG (property applied after the file)
// effective level of org.hibernate.SQL: DEBUG (only set by the property)

This is convenient: the XML defines the appenders and the format, and levels can be changed per environment with properties or environment variables such as LOGGING_LEVEL_COM_SHOP=DEBUG.

4Why logging.file.name Seems to Stop Working

logging.file.name (a full file name) and logging.file.path (a directory, in which Boot writes spring.log) switch on file output, but only through Boot's own default configuration. When we provide our own file, our file decides which appenders exist. Boot still sets system properties such as LOG_FILE and LOG_PATH from those settings, but if our XML has no appender that uses them, no file is written.

The fix is to include Boot's building blocks instead of rewriting them. Boot ships defaults.xml (conversion rules and default patterns), console-appender.xml, file-appender.xml, and base.xml, which combines them with a root logger.

XML
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/> <!-- uses LOG_FILE -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/> <!-- now logging.file.name=logs/app.log writes a file -->
</root>
<logger name="com.shop.audit" level="INFO"/>
</configuration>

5Logging.config and Log4j2

logging.config points Boot to an explicit file, for example logging.config=classpath:logging/logback-prod.xml or a path on disk. Boot then loads that file instead of searching the classpath, and if the file name does not end in -spring, the Spring tags still work because Boot is the one loading it; the early self-configuration by Logback simply finds no logback.xml.

The same rules exist for Log4j2. With spring-boot-starter-log4j2 on the classpath instead of the Logback starter, Boot looks for log4j2-spring.xml, supports the <SpringProfile> element and Spring property lookups, and applies logging.level.* after the file. A plain log4j2.xml is read by Log4j2 itself, early, without the Spring extensions.

6Follow-up questions

Why can logging during very early startup lose your custom format?

Because the first log lines are written before Spring Boot has configured logging. Until the Environment is prepared, Logback runs with whatever it found on its own: a plain logback.xml, or its default console configuration if there is only logback-spring.xml. Code that logs in a static initializer, a custom EnvironmentPostProcessor or the main method before SpringApplication.run uses that early setup, so those lines appear in a different format or are lost. Boot itself defers its own early messages and replays them once logging is configured, but our code does not get that treatment.

Can I have both logback.xml and logback-spring.xml?

It is a bad idea. Logback loads logback.xml early by itself, and Boot looks for the standard names before the -spring variants, so logback.xml would win and logback-spring.xml would be ignored. Keep exactly one file, and name it with the -spring suffix if it uses Spring features.

Where should logback-test.xml live?

Only in src/test/resources, so it is on the test classpath and never in the built jar. Logback gives logback-test.xml priority over logback.xml, so a copy that slips into a library jar can change logging for every application that depends on it.

7Conclusion

In this answer, we saw that logback.xml is read by Logback itself, very early and without Spring, while logback-spring.xml is read by Spring Boot's LoggingSystem after the Environment is ready, which is why only the -spring file supports <springProfile> and <springProperty>. logging.level.* properties are applied after the file and win over it; logging.file.name and logging.file.path need Boot's default configuration or an included file-appender.xml; logging.config selects an explicit file; and Log4j2 follows the same rules with log4j2-spring.xml.

What to say in the interviewAbout 70 seconds aloud

Open with

logback.xml is a plain Logback file. Logback finds it on the classpath and configures itself the moment the first logger is created, which in a Boot application is before the Spring Environment exists, so it can't see profiles or application properties. logback-spring.xml is not read by Logback on its own; Spring Boot's LoggingSystem loads it once the Environment is prepared, and because Boot loads it, it supports springProfile blocks and springProperty to pull values from the Environment.

Then, if they want more

That's why Boot recommends the -spring name. As for properties, after the file is loaded Boot applies logging.level properties on top, so logging.level.com.shop=DEBUG wins over a level in the XML. logging.file.name and logging.file.path only produce a file through Boot's default configuration.

With a custom file, my XML decides the appenders, so I include Boot's defaults.xml, console-appender.xml and file-appender.xml, or base.xml, and then those properties work again because the included appender uses LOG_FILE. logging.config lets me point to a specific file, and Log4j2 has the same model with log4j2-spring.xml.

One practical consequence is that anything logged before Boot configures logging, for example in a static initializer, uses Logback's default format.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "In a Spring Boot application, what is the difference between logback.xml and...": https://scrivio-interview-library.netlify.app/java/java-logging/e7c005420b/