Fixing Duplicate Logging in Spring Boot with Logback and Log4j2

Spent 25 minutes wondering why my Spring Boot application was logging the same message twice. The code looked fine: @Slf4j @Service public class OrderService {   public void processOrder(Order order) {     log.info("Processing order: {}", order.getId());     // processing logic   } } No errors. App worked fine. But every log message appeared twice in the console. The problem: I had both Logback and Log4j2 on the classpath. Spring Boot auto-configured both logging frameworks. The fix: Exclude one of them in pom.xml. <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> One exclusion. That was it. Spring Boot does not warn you when multiple logging frameworks are on the classpath. It just logs everything twice. What duplicate logging issue has caught you off guard? #Java #SpringBoot #Debugging #BackendDevelopment

Duplicate logging is tricky because the app works fine otherwise. Now I always check for conflicting logging dependencies when I see repeated log entries. A quick mvn dependency:tree helps catch this early.

Like
Reply

Even debugging dependencies in general, just happens more often than I thought it would. I've been surprised how often the pom.xml ends up being where the bug was

See more comments

To view or add a comment, sign in

Explore content categories