Ev3rlasting
Ev3rlasting

Reputation: 2495

What is the difference between Log4j, SLF4J and Logback?

I am little bit confused by these three logger libraries. It seems like that they can do the similar thing in Java logging...

Upvotes: 136

Views: 85680

Answers (3)

Philippe Cloutier
Philippe Cloutier

Reputation: 599

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.

Upvotes: 13

Avishek Bhattacharya
Avishek Bhattacharya

Reputation: 6974

This link : https://medium.com/@krishankantsinghal/logback-slf4j-log4j2-understanding-them-and-learn-how-to-use-d33deedd0c46

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.

Upvotes: 13

Andreas
Andreas

Reputation: 159096

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.

Upvotes: 188

Related Questions