使用 SLF4J 库而不是 Apache Log4j 是否还有其他优势?

Are there any additional advantages to use SLF4J library instead of Apache Log4j?

我之前遇到过这个用于日志记录的库 slf4j in my assignment. I have used apache log4j 库,但是从文档中我无法理解 slf4j 库的用例。 (脸掌) 谁能告诉我使用 SLF4j 的优势或可能的真实案例。

根据SLF4J Website(粗体注释是我做的):

The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction 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.

因此,SLF4J 库似乎提供了所使用的底层日志记录框架的抽象。根据他们的网站,这将允许您编写独立于使用的日志记录框架的应用程序,因为 SLF4J 覆盖了底层日志记录机制。因此,就您的应用程序而言,它不会关心您使用的底层日志记录机制。