Difference between slf4j-log4j12 and log4j-slf4j-impl
Asked Answered
K

1

16

In some projects which used slf4j and log4j I can see dependencies like

compile('org.apache.logging.log4j:log4j-core:version')
compile('org.apache.logging.log4j:log4j-api:version')
compile('org.apache.logging.log4j:log4j-slf4j-impl:version')

But some projects use slf4j-log4j12 instead of log4j-slf4j-impl. To my understanding they are both works like bridges between slf4j and log4j, but what's their difference?

Kidder answered 30/12, 2021 at 6:34 Comment(0)
B
21

Those artifacts use different versions of Log4j:

  • slf4j-log4j12 is a bridge between SLF4J and Log4j 1.2. Its versioning follows SLF4J.
  • slf4j-reload4j is a bridge between SLF4J and Reload4j (a clone of Log4j 1.2). Its versioning follows SLF4J.
  • log4j-slf4j-impl is a bridge between SLF4J 1 (up to 1.7.x) and Log4j 2 API. Its versioning follows LOG4J2.
  • log4j-slf4j2-impl is a bridge between SLF4J 2 (or higher) and Log4j 2 API. Its versioning follows LOG4J2.

Since Log4j 1.x reached end-of-life more than 7 years ago, there is no sense in using the first one in new software.

Brittaneybrittani answered 30/12, 2021 at 6:58 Comment(10)
So, slf4j-log4j has no 2.x counterpart? If I upgrade to log4j2 I have to use log4j-slf4j-impl?Kidder
Yes, the SLF4J project released only a binding for Log4j 1.x (there will be no slf4j-log4j2 artifact). The binding for Log4j 2.x is maintained by the Log4j project itself.Brittaneybrittani
RBB, you have to use log4j-slf4j-impl assuming you are still on SLF4J 1, yes.Walhalla
So which other dependencies (apart from log4j-slf4j-impl) should I add to my pom in order to use log4j2 with slf4j1x ?Burnout
Technically log4j-slf4j-impl is just a bridge between SLF4J and Log4j API. You also should add a Log4j API implementation (e.g. log4j-core).Brittaneybrittani
There seems to be a misunderstanding of the concept in this answer. "Bridge" and "Binding" is different. All list in this answer is binding. slf4j.org/legacy.htmlAneto
@HeedoLee: the difference between "binding" and "bridge" is not well defined. The nomenclature is not even consistent in SLF4J: SLF4J 1 calls its implementations "bindings", while SLF4J 2 calls its implementations "providers".Brittaneybrittani
@PiotrP.Karwasz In terms of SLF4J, these term have specific meaning. "Bridge" is redirection from Some (legacy) logging component to SLF4J. But "binding" is redirection from SLF4J to some logging framework. This is absolutely different concept. Suppose you have bridge for "A" and binding for "B". If some log is triggered by "A", then this log is passed to SLF4J and eventualy passed to "B". Binding and provider is same concept. It is just renaming. However, the concepts between bridge and binding (or provider) are clearly different and should be distinguished.Aneto
The difference between the two depends on the point of view: log4j-slf4j-impl is a binding from SLF4J perspective, but it is a bridge (from a legacy/older API) from the perspective of Log4j API.Brittaneybrittani
Yes, you are right. But when talking about slf4j, why do we need to change the perspective to log4j? Also, it is clear that slf4j distinguishes between the two, and calling them interchangeably can cause confusion.Aneto

© 2022 - 2024 — McMap. All rights reserved.