Whats the difference between log4j and apache commons logging?

时间:2015-12-14 18:07:55

标签: java logging log4j

I am very new to this and I am trying to add logging on our service end. I found that I can simply use the following for logging:

<code>
    private Log logger = LogFactory.getFactory()
        .getInstance(MyClass.class);
    logger.debug("test1234");
</code>

Then I also found another framework called log4j which I am not sure if is useful to me. I just want to know the difference between using log4j framework and apache commons logging. Thanks in advance

1 个答案:

答案 0 :(得分:2)

Apache Commons Logging是一种抽象,允许您编写日志代码而无需关心实际的日志记录实现。这在编写库代码时特别有用,因为库的用户可能使用的是不同的日志库。

请注意,不再推荐使用公共日志记录,而应使用SLF4J。这来自commons logging的作者,所以它非常权威;)