Luciano Fiandesio
Luciano Fiandesio

Reputation: 10215

Why does spring-boot-starter-logging require a dependency on log4-to-slf4j

I have a Spring Boot 2.6.3 project that uses spring-boot-starter. When I run the dependecy:tree goal in maven, I see that spring-boot-starter-logging depends on both logback and (indirectly) log4j. Why does spring-boot-starter-logging require a dependency on log4-to-slf4j?

enter image description here

Upvotes: 6

Views: 6555

Answers (1)

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16185

Spring Boot has bindings for all major logging frameworks. With a single configuration you can concentrate logs sent through SLF4J, Log4j 2.x API or java.util.logging.

Therefore the spring-boot-starter-logging provides:

  • a logging backend (logback-classic), which uses SLF4J as native API,
  • a bridge from the Log4j 2.x API to SLF4J (log4j-to-slf4j). Remark that this is not the standard Log4j 2.x Core implementation.
  • a bridge/handler from java.util.logging to SLF4J (jul-to-slf4j).

Remark that spring-boot-starter-log4j2 does the same thing and redirects the frameworks above to Log4j 2.x Core.

The big absent in this picture is Jakarta Commons Logging, which is only able to bind to java.util.logging (hence not directly to neither Logback nor Log4j 2.x Core). However spring-core depends on spring-jcl, which binds JCL directly to SLF4J or the Log4j 2.x API and can entirely replace the original JCL.

A fifth API (Log4j 1.x) was supported in Spring Boot 1.x.

Upvotes: 4

Related Questions