Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 280
Ev3rlasting Avatar asked Sep 18 '16 21:09

Ev3rlasting


People also ask

Is Logback the same as SLF4J?

Logback and SLF4J can be primarily classified as "Log Management" tools. According to the StackShare community, Logback has a broader approval, being mentioned in 4 company stacks & 9 developers stacks; compared to SLF4J, which is listed in 5 company stacks and 7 developer stacks.

What is Logback and SLF4J?

Logback. Java Logging. SLF4J (Simple Logging Facade for Java) is a simple facade or abstraction for various logging frameworks, such as Java Util Logging (JUL), Logback and Log4j2. We use the abstract SLF4J API in the application, and later we can plug in any desired logging framework as underlying implementation.

What is difference between SLF4J and log4j?

Unlike log4j, SLF4J (Simple Logging Facade for Java) is not an implementation of logging framework, it is an abstraction for all those logging frameworks in Java similar to log4J. Therefore, you cannot compare both. However, it is always difficult to prefer one between the two.

Does SLF4J support Logback?

SLF4J supports popular logging frameworks, namely log4j, java. util. logging, Simple logging and NOP. The logback project supports SLF4J natively.


2 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.

like image 104
Andreas Avatar answered Oct 05 '22 16:10

Andreas


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.

like image 30
Avishek Bhattacharya Avatar answered Oct 05 '22 16:10

Avishek Bhattacharya