【问题标题】:Mix SLF4J with Log4J将 SLF4J 与 Log4J 混合
【发布时间】:2012-02-28 10:23:32
【问题描述】:

我有一个实现 SLF4J 接口的记录器和一个在类路径上实现 org.slf4j.spi.LoggerFactoryBinder 的类 org.slf4j.impl.StaticLoggerBinder,因为它与其他必需的依赖项位于同一个 jar 中。

现在我想在一个项目中使用 Log4J-Logger,只使用Log4J 接口,但依赖于其他使用 SLF4J 的库。因此,我将不得不将SLF4J-LOG4J-Bridge 扔到类路径中。

我想知道我的org.slf4j.impl.StaticLoggerBinder 是否会干扰SLF4J-LOG4J-Bridge。我必须删除我的org.slf4j.impl.StaticLoggerBinder 才能让LOG4J-Logger 工作。或者换个方式问:SLF4J-LOG4J-Bridge 是否也实现了org.slf4j.impl.StaticLoggerBinder

【问题讨论】:

    标签: java log4j logging slf4j


    【解决方案1】:

    org.slf4j.impl.StaticLoggerBinder 是一个类而不是一个接口。

    如果你去http://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12/1.6.4,下载并打开jar你会看到它不包含StaticLoggerBinder类。

    【讨论】:

    • 谢谢,我从来没有说过 org.slf4j.impl.StaticLoggerBinder 是一个接口。使用 brigde 的优先级是否高于实现 StaticLoggerBinder?
    • 我从 SLF4J-LOG4J-Bridge 是否也实现 org.slf4j.impl.StaticLoggerBinder 来理解它? SLF4J-LOG4J-Bridge 不包含 StaticLoggerBinder 所以这个类不会干扰干扰。
    猜你喜欢
    • 2014-10-31
    • 1970-01-01
    • 2018-10-07
    • 2023-04-09
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 2014-11-18
    • 2020-07-13
    相关资源
    最近更新 更多