Completely remove log4j

Viewed 600

I have a brand new test project from start.spring.io, with the following gradle file:

plugins {
  id 'org.springframework.boot' version '2.6.2'
  id 'io.spring.dependency-management' version '1.0.11.RELEASE'
  id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
  mavenCentral()
}

dependencies {
  implementation 'org.springframework.boot:spring-boot-starter-web'
  testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
  useJUnitPlatform()
}

When looking at dependencies, I get the following:

|    |    +--- org.springframework.boot:spring-boot-starter-logging:2.6.2
|    |    |    +--- ch.qos.logback:logback-classic:1.2.9
|    |    |    |    +--- ch.qos.logback:logback-core:1.2.9
|    |    |    |    \--- org.slf4j:slf4j-api:1.7.32
|    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.17.0
|    |    |    |    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.32
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.0
|    |    |    \--- org.slf4j:jul-to-slf4j:1.7.32
|    |    |         \--- org.slf4j:slf4j-api:1.7.32

How can I completely remove log4j from the project and what should my gradle file look like? I would like to use logback exclusively.

1 Answers

You're already free of log4j.

If your dependencies don't include the log4j core jar, then you're not logging to log4j. The api jar doesn't have any functionality. The api jar together with the log4j-to-slf4j jar make sure that any dependency that is written to use log4j directly has its logging redirected to slf4j, which will use logback.

Related