How to disable Logback in Spring Boot
Codemia Knowledge Hub ·
To disable Logback in Spring Boot, exclude the logback-classic and logback-core artifacts from spring-boot-starter in your build file, then add the logging framework you want to use instead. Logback is Spring Boot's default logging implementation, so it stays on the classpath unless you remove it explicitly.
Why you might remove Logback
- Different logging framework: The application needs another framework, such as Log4j2.
- Performance: Another framework's performance characteristics may suit you better.
- Centralized logging: In a microservices setup, a centralized solution like ELK or Splunk may call for a different logging configuration.
- Dynamic configuration: Replacing Logback can let you change logging configuration without restarting the application.
Exclude the Logback dependencies
Maven: add exclusions to the spring-boot-starter dependency in pom.xml:
Gradle: exclude the same modules in build.gradle:
Profile-specific configuration
Spring Profiles give you different configuration per environment. Put environment-specific properties in application-{profile}.properties or application-{profile}.yaml and exclude Logback there.
Custom configuration and SLF4J
- Conditional beans: Define logging beans in a
@Configurationclass with conditional properties that decide when Logback is enabled or disabled. - SLF4J: SLF4J is a logging facade, not a backend. If you code against it, make sure the API is declared in
pom.xml:
Then add an SLF4J binding (for example to Log4j2) or a console logger.
What can go wrong after removing Logback
- Unnoticed errors: With no logger in place, unhandled exceptions can go unseen and lead to failures.
- Performance: A weaker replacement can degrade performance.
- Gaps in logs: Configuration mistakes can leave logging data incomplete, which makes debugging and operations harder.
| Task | Description |
| Exclude Logback Dependencies | Remove Logback from pom.xml or build.gradle using exclusion. |
| Use Spring Profiles | Define custom log configuration for each profile to exclude Logback. |
| Custom Configuration | Create a custom configuration class to enable/disable Logback dynamically. |
| Implement Alternative Logging | Use SLF4J or a similar logging framework; ensure bindings are correctly set. |
| Evaluate Impact | Analyze the operational and performance impacts of replacing Logback. |
Test the new logging setup in a development environment before promoting it to production.
Related reading
- Disabling network logs on Kubernetes when running kubectl exec
- Disadvantages of using eureka for Service Discovery with kubernetes
- Distribute children elements or the top-level parent elements among monitoring hosts
- Distributed application - is load balancer single point of failure?
- Disable redis when many timeouts using spring boot
- Disable security for unit tests with spring boot
- distributed cache with hazelcast
- Distributed data storage infrastructure for storage of video streams
System design interview problems on this topic
- Design a Metrics Monitoring and Alerting System: solution and walkthrough
- Design a Distributed Tracing System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.