Log4j是commons-logging还是slf4j的实现?[英] Log4j is implementation of commons-logging or slf4j?

本文是小编为大家收集整理的关于Log4j是commons-logging还是slf4j的实现?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

hy,

我已经读到Commons-Logging和SLF4J是记录的"接口或规格",您必须插入实现.但是我已经读到,您可以使用log4j,例如使用Commons-Loging和SLF4J,因此:log4j同时使用Commons-Logging和SLF4J的规格?我不明白

谢谢

推荐答案

SLF4J是伐木外墙,可以引入Log4J和Commons-Goging项目.因此,您使用SLF4J类执行日志记录,就像外墙一样.在下面,您可以拥有log4j或SLF4J支持的任何其他日志记录系统.这样做的优势在于,SLF4J可以使您从绑定到特定的日志记录系统.

其他推荐答案

sl4j和Commons-Loging都是基础记录实现(例如Log4J或JDK Logging)的立面.他们通过拥有自己的日志界面,多个实现,每个实现都包裹混凝土记录框架的记录器接口来起作用.因此,在log4j示例中,slf4j的org.slf4j.logger接口具有包装log4j org.apache.log4j.logger的实现,而不是相反.同样的机制适用于公地.这可以使用log4j独立,与SLF4J或Commons-Logging一起使用.

本文地址:https://www.itbaoku.cn/post/1575169.html

问题描述

Hy,

I have read that commons-logging and slf4j are "interfaces or specifications" for logging and you have to plugin an implementation. But I have read that you can use log4j for example with commons-logging and with slf4j too, so: log4j "implements" the specifications of commons-logging and slf4j at the same time? I dont understand it

Thanks

推荐答案

SLF4j is a logging facade and can be introduced into both Log4j and commons-logging projects. So you use SLF4j classes to perform the logging it just acts like a facade. Underneath, you can have either Log4j or any other logging system that is supported by SLF4j. The advantage by doing so is that SLF4j relives you from getting tied to a specific logging system.

其他推荐答案

Sl4j and commons-logging are both facades for underlying logging implementations such as log4j or JDK logging. They work by having their own logging interface, whith multiple implementations, each implementation wrapping the logger interface of the concrete logging framework. So, in the log4j example, Slf4j's org.slf4j.Logger interface has an implementation which wraps a Log4j org.apache.log4j.Logger, not the other way around. The same mechanism applies with commons-logging. This enables using Log4j standalone, with Slf4j or with commons-logging, as you wish.