I am little bit confused by these three logger libraries. It seems like that they can do the similar thing in Java logging...
-
1They do similar things. They have different APIs. I would use the one you like best. BTW have a look at log4j2 rather than log4j. – Peter Lawrey Sep 18 '16 at 21:44
-
4@PeterLawrey With the exception of slf4j, which isn't a logger in itself (it is a facade to provide a consistent api to *another* logger). – Elliott Frisch Sep 18 '16 at 21:45
-
@ElliottFrisch good point though I use slf4j-simple which doesn't require another logger. – Peter Lawrey Sep 18 '16 at 21:47
-
6Why the question gets 2negative votes? – Prashant Prabhakar Singh May 11 '17 at 05:54
-
4Some benchmark here: https://www.loggly.com/blog/benchmarking-java-logging-frameworks/ – Foyta Aug 24 '18 at 14:49
-
Welcome to the bazaar ! – Arfur Narf May 13 '23 at 02:08
3 Answers
Check out their home pages:
SLF4J - The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction1 for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time.
1) It is not itself a logging library, but a generic interface to one of many logging libraries.
Log4j 1.2 - Welcome to Apache log4j, a logging library for Java.
Logback - Logback is intended as a successor to the popular log4j project, picking up where log4j leaves off.
Log4j 2 - Apache Log4j 2 is an upgrade to Log4j that provides significant improvements over its predecessor, Log4j 1.x, and provides many of the improvements available in Logback while fixing some inherent problems in Logback's architecture.
At least, that's what they all say of themselves.

- 154,647
- 11
- 152
- 247
-
5So with SLF4J as a facade, we can use either log4j or logback or
. Is it? – Shekhar Jan 13 '20 at 15:12 -
3
-
It is not quite correct that SLF4J is not a logging library. It is a logging library, in particular when using the slf4j-simple provider. – Philippe Cloutier May 02 '23 at 21:36
-
@PhilippeCloutier No one considers SLF4J a "logging library". It is an API. The Simple Logger it provides is rarely used. – rgoers May 11 '23 at 04:44
Explains the differences in detail.
Quoting from there
Slf4j
So Basically Simple Logging Facade for Java serves as a simple facade or abstraction for various logging frameworks allowing the end user to plug in the desired logging framework at deployment time.
log4j2
Log4j,Logback and java.util.Logger are logging libraries which actually write the logs and have their own pros and cons. As industry standards are Log4j2 and logback
I would recommend going through the blog. It provides all the glory details how both are used with adapter.

- 6,534
- 3
- 34
- 53
-
The article you reference has some valuable information but is of low quality. It includes incorrect information (including a major mistake reported in a comment). It has some interesting graphics, but I assume some are in violation of SLF4J's copyrights. I'm therefore downvoting this to favor Andreas's far from perfect but IMO better answer. – Philippe Cloutier May 02 '23 at 20:53
Your question is far from easy, and only covers some of the main elements of the Java ecosystem's ridiculously complicated logging. I do not know that ecosystem enough to fully describe it, but describing the current situation well and how it came to be would surely require days/weeks of work to write what would resemble a book.
Here is a very short, surely simplistic answer focusing on the elements you mentioned.
Log4j appeared as a flexible logging library in 2001.
Logback was developed as a more powerful alternative to Log4j from 2006 to 2011. The Simple Logging Facade for Java (SLF4J) was developed between 2005 and 2006 as a superior alternative to [Apache/Jakarta] Commons Logging (JCL). Logback and SLF4J are complementary (they can be used together, or not).
Perhaps because Logback and SLF4J are to a small degree commercial, the Apache Foundation released in 2014 a major upgrade to Log4j. Log4j 2 is somewhat comparable to Logback+SLF4J, in that it provides a facade API (log4j-api, comparable to SLF4J) as well as an implementation (log4j-core, comparable to Logback).
If the above seems to contradict other sources, that may be because Log4j version 1 was very different and remains in use, so sources describing "Log4j" may in fact still describe Log4j 1.

- 156
- 10
-
Nice answer! Log42 (or better Log4j2 API+Log4j2 Core) is even **exactly** as SLF4J+Logback: both are developed by a single entity (Ceki Gülcü for SLF4J+Logback, the Apache Logging Services PMC for Log4j2 API+Log4j2 Core), both backends are mainly driven by changes in their API (and viceversa). Also both APIs can work with both backends. – Piotr P. Karwasz May 03 '23 at 10:39
-
Log4j and SLF4J+Logback are *comparable*, but while Log4j is one solution, I would consider Logback and SLF4J as highly *complementary* products. Unlike Log4j, SLF4J for instance features slf4j-simple, which allows to use it alone, without Logback. Whereas Logback offers logback-classic, a module which enables integration with SLF4J. It may be a nuance, but I'd rather not oversimplify, because the topic is already complicated enough! – Philippe Cloutier May 04 '23 at 14:37
-
That is IMHO a misconception, due to the fact that Log4j2 API and Log4j2 Core share a common name. Like SLF4J, Log4j2 API has a simple binding (it is included in `log4j-api`) and bindings to all major logging frameworks (i.e. Logback, `java.util.logging` and JBoss LogManager). It only lacks a binding to Log4j 1.x for obvious reasons. – Piotr P. Karwasz May 04 '23 at 16:15
-
Hum, interesting. If log4j-api *includes* "a simple binding" to itself, I guess that's more of an implementation that a *binding proper*, but regardless, I can't find any documentation of that. It's not that I really question your say, but surely such a feature would be documented somewhere? – Philippe Cloutier May 05 '23 at 17:58
-
Documentation is hard to come by. To configure a [`SimpleLoggerContext`](https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/simple/SimpleLoggerContext.html) you use system properties, which are [documented here](https://logging.apache.org/log4j/2.x/manual/configuration.html#system-properties). From time to time a [question like this](https://stackoverflow.com/q/72115612/11748454) pops up. – Piotr P. Karwasz May 05 '23 at 22:15
-