logback Demo 问题
第一次,填坑!
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.
官网的解决:https://www.slf4j.org/codes.html#noProviders
再回过来看代码:
pom.xml
<!--slf4j-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<!--logback-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.2.3</version>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
Test1.java
package com.evhtech.test;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Test1 {
public static void main(String[] args) {
log.debug("Hello, this is a line of log message logged by Logback world");
log.info("Hello, this is a line of log message logged by Logback world");
log.error("Hello, this is a line of log message logged by Logback world");
}
}
运行main方法,依旧没有日志信息:
SLF4J: Class path contains multiple SLF4J providers.
SLF4J: Found provider [org.slf4j.helpers.NOPServiceProvider@65b54208]
SLF4J: Found provider [org.slf4j.simple.SimpleServiceProvider@1be6f5c3]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual provider is of type [org.slf4j.helpers.NOPServiceProvider@65b54208]
日志第一信息:说:类路径中包含多个SLF4J提供者。
第二次,填坑!
向pom.xml中再添加依赖
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.8.0-beta4</version>
</dependency>
再次运行:
SLF4J: Class path contains multiple SLF4J providers.
译:类路径中包含多个SLF4J提供者。
第三次,填坑!
提供者多个,那就删除3个依赖,留一个。再运行下。
pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.8.0-beta4</version>
</dependency>
这回就可以了:
有时候面对这种问题只能一点一点的尝试。顺带分析下,履下。