SpringBoot
Logback
Logging
Configuration
Java

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

  1. Different logging framework: The application needs another framework, such as Log4j2.
  2. Performance: Another framework's performance characteristics may suit you better.
  3. Centralized logging: In a microservices setup, a centralized solution like ELK or Splunk may call for a different logging configuration.
  4. 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:

xml
1   <dependency>
2       <groupId>org.springframework.boot</groupId>
3       <artifactId>spring-boot-starter</artifactId>
4       <exclusions>
5           <exclusion>
6               <groupId>ch.qos.logback</groupId>
7               <artifactId>logback-classic</artifactId>
8           </exclusion>
9           <exclusion>
10               <groupId>ch.qos.logback</groupId>
11               <artifactId>logback-core</artifactId>
12           </exclusion>
13       </exclusions>
14   </dependency>

Gradle: exclude the same modules in build.gradle:

groovy
1   dependencies {
2       implementation('org.springframework.boot:spring-boot-starter') {
3           exclude module: 'logback-classic'
4           exclude module: 'logback-core'
5       }
6   }

Profile-specific configuration

Spring Profiles give you different configuration per environment. Put environment-specific properties in application-&#123;profile&#125;.properties or application-&#123;profile&#125;.yaml and exclude Logback there.

Custom configuration and SLF4J

  • Conditional beans: Define logging beans in a @Configuration class 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:
xml
1   <dependency>
2       <groupId>org.slf4j</groupId>
3       <artifactId>slf4j-api</artifactId>
4   </dependency>

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.
TaskDescription
Exclude Logback DependenciesRemove Logback from pom.xml or build.gradle using exclusion.
Use Spring ProfilesDefine custom log configuration for each profile to exclude Logback.
Custom ConfigurationCreate a custom configuration class to enable/disable Logback dynamically.
Implement Alternative LoggingUse SLF4J or a similar logging framework; ensure bindings are correctly set.
Evaluate ImpactAnalyze the operational and performance impacts of replacing Logback.

Test the new logging setup in a development environment before promoting it to production.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design