我正在学习Spring Boot。但是我完全搞砸了伐木工的依赖关系。 我有一个简单的POM:在Spring Boot中使用log4j2进行日志记录
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
我在..src \主\资源创建log4j2.xml \
我有这样的记录:
private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);
LOG.error("ERRRRRRR!!!!");
但是,当我开始看到:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/me/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/me/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.3/log4j-slf4j-impl-2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
当然,log4j2及其配置不起作用。
我知道,这是一个很流行的问题。我搜索了很多答案,但没有为我工作。
我现在还不确定。我是新手,刚开始学习所有这些。谢谢,我会继续使用Logback。 – user3742622
对于它我在POM或其他方面无能为力,Logback默认是有的,对不对? – user3742622
阅读logback文档以使用logback配置日志记录,并删除与log4j相关的依赖项。或者阅读关于日志的春季启动文档。 – Toilal