SLF4J Vs Log4j



What is log4j?

log4j is a reliable, fast and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License.

log4j is highly configurable through external configuration files at runtime. It views the logging process in terms of levels of priorities and offers mechanisms to direct logging information to a great variety of destinations, such as a database, file, console, UNIX Syslog, etc. (for more details on log4j refer our Tutorial).

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

If you have a choice, logging abstraction is always preferable than logging framework. If you use a logging abstraction, SLF4J in particular, you can migrate to any logging framework you need at the time of deployment without opting for single dependency.

Observe the following diagram to have a better understanding.

Application
Advertisements