问题描述
我已经读到commons-logging和slf4j是用于日志记录的接口或规范",您必须插入一个实现.但是我已经读到您也可以将log4j与commons-logging和slf4j一起使用,因此:log4j同时实现" commons-logging和slf4j的规范吗?我不明白
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
谢谢
推荐答案
Sl4j和commons-logging都是诸如log4j或JDK日志记录之类的基础日志记录实现的基础.他们通过拥有自己的日志接口和多个实现来工作,每个实现都包装了具体日志框架的logger接口.因此,在log4j示例中,Slf4j的org.slf4j.Logger接口具有实现,该实现包装了Log4j org.apache.log4j.Logger,而不是相反.相同的机制适用于commons-logging.这样便可以根据需要将Log4j独立地与Slf4j或commons-logging一起使用.
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.
这篇关于Log4j是commons-logging还是slf4j的实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!