Slf4j 简明教程

SLF4J - Overview

SLF4J 代表 S*imple *L*ogging *F*acade for *J*ava. It provides a simple abstraction of all the logging frameworks in Java. Thus, it enables a user to work with any of the logging frameworks such as Log4j, Logback and *JUL (java.util.logging),使用单一依赖。你可以在运行时/部署时迁移到所需的日志记录框架。

SLF4J stands for S*imple *L*ogging *F*acade for *J*ava. It provides a simple abstraction of all the logging frameworks in Java. Thus, it enables a user to work with any of the logging frameworks such as Log4j, Logback and *JUL (java.util.logging) using single dependency. You can migrate to the required logging framework at run-time/deployment time.

Ceki Gülcü 创建了 SLF4J 作为 Jakarta commons-logging 框架的替代品。

Ceki Gülcü created SLF4J as an alternative to Jakarta commons-logging framework.

slf4j api jar

Advantages of SLF4J

以下是 SLF4J 的优点:

Following are the advantages of SLF4J −

  1. Using SLF4J framework, you can migrate to the desired logging framework at the time of deployment.

  2. Slf4J provides bindings to all popular logging frameworks such as log4j, JUL, Simple logging and, NOP. Therefore, you can switch to any of these popular frameworks at the time of deployment.

  3. SLF4J provides support to parameterized logging messages irrespective of the binding you use.

  4. Since SLF4J decouples application and logging framework, you can easily write applications independent of logging frameworks. You need not bother about the logging framework being used to write an application.

  5. SLF4J provides a simple Java tool known as migrator. Using this tool, you can migrate existing projects, which use logging frame works like Jakarta Commons Logging (JCL) or, log4j or, Java.util.logging (JUL) to SLF4J.