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

Switching from Logback to Log4j2 in a Spring Boot app mainly requires changing dependencies and the logging configuration file, not the application's logging calls, since both sit behind the SLF4J facade.

Key Points

Example

A team migrating for Log4j2's async logging performance benefits swaps the starter dependency and configuration file, but their hundreds of existing log.info(...) and log.error(...) calls throughout the codebase don't need to change at all.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

Interview Tip

A concise interview answer is

I'd exclude the default Logback starter, add spring-boot-starter-log4j2, and replace logback.xml with a log4j2.xml configuration. Since our code logs through the SLF4J facade rather than a framework-specific API, none of the actual logging calls in the codebase need to change.

Last updated: 11 November 2026

Previous question: How do you set up logging in Spring Boot?

Next question: How do you connect to multiple databases in a Spring Boot application?

More Spring Boot - Level IV (Advanced) interview questions

All Spring Boot - Level IV (Advanced) questions