Slf4j 简明教程

SLF4J Vs Log4j

What is log4j?

Log4j 是一个可靠、快速且灵活的 logging framework (APIs) written in Java ,它在 Apache 软件许可证下分发。

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

Log4j 可以通过外部配置文件在运行时进行高度配置。它将日志记录过程视为具有优先级,并提供将日志记录信息定向到各种目的地的机制,例如数据库、文件、控制台、UNIX Syslog 等(有关 Log4j 的更多详细信息,请参阅我们的 Tutorial )。

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

与 log4j 不同,SLF4J( S*imple *L*ogging *F*acade for *J*ava) is not an implementation of logging framework, it is an *abstraction for all those logging frameworks in Java similar to log4J 。因此,您无法对比两者。不过,在两者之间做出取舍总是困难的。

Unlike log4j, SLF4J (S*imple *L*ogging *F*acade for *J*ava) 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.

如果您有选择,日志记录抽象总是优于日志记录框架。如果您使用日志记录抽象,特别是 SLF4J,则您可以在部署时迁移到任何需要的日志记录框架,而无需选择单一依赖关系。

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