为支持各类不同的日志系统,SLF4J(Simple logging Facade for Java)提供了一套抽象层API或者通用库,它方便开发者集成不同的应用而不需要修改各个子系统的日志。
下面我们就来说说如何集成slf4j
Springboot 1.5.1 中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
已经引入slf4j的库了,所以不需要在pom.xml刻意引入它的jar包,也不需要再做任何配置。
Springboot 1.5.1默认使用的是logback日志框架,所以只要做简单的配置就可以使用,在maven web 工程的resources 下创建一个logback.xml的配置文件,内容为
version="1.0" encoding="UTF-8" standalone="no"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.liting" level="TRACE" />
<logger name="XXX.XXX" level="ERROR" />
</configuration>
xxx.xxx代表你要设置日志级别的包名,level为日志级别。application.properties加上日志输出的位置logging.file = X:\xxx\xxx\xxx.log
此时, springboot就可以正常使用logback日志系统了。
可以写段代码测试一下
private Logger logger = LoggerFactory.getLogger(this.getClass());
public void