slf4j和Log4j、log4j2日志使用

强颜欢笑 提交于 2020-01-07 01:53:01

【推荐】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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!