Logback ,SLF4J , Log4J2. Understanding them and learn how to use.
If you are working or worked on any java project, you might have logged some debug ,error or info statements for debugging or tracking purpose. Those statements are written by logging libraries to a file on disk or on some other medium.
Logging is a critical aspect of any project, so various framework has been written . some of java logging framework are Log4j ,logback , Apache common logging, java.util.Logger etc. All these logger do the work of logging your logs to file or other specified media.
What is SLF4J
SLF4j stands for Simple Logging Facade for java. As name suggest it is a facade library which provide abstraction for logging libraries like log4j, logback , java.util.logger. and don't do actual logging.
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.
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. Log4j1.x has been deprecated in 2015.
So question arises why to use slf4j instead of using log4j2 or logback directly?
We can directly use log4j2 without slf4j. But you are now locked to log4j2 library. So in future if you want to move to any other logging library. you have to go…