【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
在使用日志时,由于jdk,spring等版本不断升级,log的版本也需要更改,所以,使用slf4-api去调用不同的日志成为编程的规范。
具体使用方法是,在slf4j和具体的日志系统中间使用桥接,实现slf4j的spi接口,同时使用具体的日志系统。
给出几套方案:
1、slf4j+log4j2
log4j核心jar包:log4j.jar
slf4j核心jar包:slf4j-api.jar
slf4j与log4j的桥接包:slf4j-log4j12.jar,这个包的作用就是使用slf4j的api,但是底层实现是基于log4j
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
1、slf4j+log4j
sl4j调用log4j,需要更换的就只是log4j-core
具体参考:https://www.jianshu.com/p/370ed25cb7c4
来源:oschina
链接:https://my.oschina.net/u/3829307/blog/3153057