在 Springmvc 开发中 slf4j-api 1.8+ 和 log4j2 2.14 版本如何绑定

2020-12-13 01:43:56 +08:00
 NoKey

今天搭建了一个 spring mvc 工程(不是 springboot )

在 mvnrepository 找了 slf4j 和 log4j2 的包

把最新版本拿了下来

pom.xml 里面按照习惯这样写的


    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.14.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.14.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.14.0</version>
    </dependency>


    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>2.0.0-alpha1</version>
    </dependency>


运行起来有提示

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/Users/xxx/develop/code/myservice/target/myservice/WEB-INF/lib/log4j-slf4j-impl-2.14.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.

然后,我根据提示的连接进去看了一下,有个说明

Planning for the advent of Jigsaw (Java 9), slf4j-api version 1.8.x and later use the ServiceLoader mechanism. Earlier versions of SLF4J relied on the static binder mechanism which is no longer honored by slf4j-api.
In case SLF4J finds no providers targeting SLF4J 1.8 but finds instead bindings targeting SLF4J 1.7 or earlier, it will list the bindings it finds but otherwise ignores them.

学艺不精。。。没搞懂我到底应该怎么做

请各位大佬赐教。。。谢谢。

1536 次点击
所在节点    编程
2 条回复
skydiver
2020-12-13 02:05:01 +08:00
NoKey
2020-12-13 11:35:47 +08:00
@skydiver 谢谢,我昨天尝试过这个包,还是有问题,可能是我启动工程有问题,今天重新启动一下就 ok 了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/734884

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX