How do you set up logging in Spring Boot?

Spring Boot achieves logging through built-in support for common logging frameworks, defaulting to Logback with sensible pre-configured settings, which can be customized via a logback.xml file.

Key Points

Example

Setting logging.level.com.example.service=DEBUG in application.yml turns on verbose logging just for that package, useful for diagnosing an issue in production without redeploying a custom logback.xml.

<!-- logback-spring.xml -->
<configuration>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>app.log</file>
        <encoder>
            <pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="INFO">
        <appender-ref ref="FILE"/>
    </root>
</configuration>

Interview Tip

A concise interview answer is

Spring Boot defaults to Logback via the SLF4J facade, so my code just calls SLF4J's Logger API. For anything beyond the defaults, I add a logback-spring.xml to control log levels, patterns, and file appenders, and use logging.level.* properties for quick, no-redeploy adjustments.

Last updated: 11 November 2026

Previous question: How would you migrate a Spring Boot application to a new database schema without downtime?

Next question: What changes are needed to switch from Logback to Log4j2 in Spring Boot?

More Spring Boot - Level IV (Advanced) interview questions

All Spring Boot - Level IV (Advanced) questions