2021-02-06 SLF No SLF4J providers were found. - Log4j2 快捷配置

首先搞清楚SLF4J和log4j是啥子关系,
然后 https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/

The Log4j 2 SLF4J Binding allows applications coded to the SLF4J API to use Log4j 2 as the implementation.
Due to a break in compatibility in the SLF4J binding, as of release 2.11.1 two SLF4J to Log4j Adapters are provided.
1. log4j-slf4j-impl should be used with SLF4J 1.7.x releases or older.
2. log4j-slf4j18-impl should be used with SLF4J 1.8.x releases or newer.
Applications that take advantage of the Java Module System should use SLF4J 1.8.x and log4j-slf4j18-impl

log4j-slf4j-impl should be used with SLF4J 1.7.x releases or older.
log4j-slf4j18-impl should be used with SLF4J 1.8.x releases or newer.
所以排查下项目正真使用的SLF4J版本是不是1.8以上的,如果是,请使用log4j-slf4j18-impl,一般是引入新依赖覆盖导致这个问题。
遇到此类问题,要灵活,比如这回是 1.7.x,下回就可能是1.6.x引起的不兼容。出现问题时多怀疑自己的代码,即使在一个相对复杂的系统中,也要仔细阅读堆栈,不要看见就头大,因为它先前肯定是运行正常的,是否正确按照说明正确使用了,每个函数的调用是否明白其含义,最近的变动是啥。

附录

log4j2 + slf4j 配置
https://howtodoinjava.com/log4j2/log4j2-with-slf4j/

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.20.0</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.20.0</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.20.0</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %l - %m%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console"/>
        </Root>
        <logger name="org.apache.http" level="debug">
            <AppenderRef ref="Console"/>
        </logger>
    </Loggers>
</Configuration>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值