Member-only story

What is the difference between SLF4j and log4J/log4j2?(Logging frameworks vs Logging wrappers in java)

Aditya
2 min readNov 5, 2020

When we create a java application, we would like to log the statements, at different logging levels( info, warn, debug, error e.t.c), so that it helps to trace the program flow while troubleshooting.So when we decide to implement logging for a given application instead of using stdout, we can use several logging frameworks available in the market like log4j, logback,log4j2, tinylog e.t.c

When we write something like “log.info(“hello world”)”, we need logic that will print “Hello world” to console, files e.t.c. So do we need to write logic to write the “Hello world” string to a file or console ? The answer is NO because Java ecosystem contains so many frameworks that contain logic to print the log statements.

For example, log4j, logback, log4j2, tinylog libraries provide implementations that will help to log statements from java program to console, file e.t.c.

So we created a project that contains say 100 classes that log and started using the log4j library for logging. One day we got a requirement stating that we need to use logback library instead of log4j due to some security concerns over log4j library. Then we need to change each and every file to replace log4j related classes with logback related classes. This will waste precious developer effort cycles, and also we are tightly coupling the code with a logging solution (like log4j or logback).

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Aditya
Aditya

Written by Aditya

Principal data engineer → Distributed Threat hunting security platform | aws certified solutions architect | gssp-java | Chicago-IL

No responses yet

Write a response