# springboot中日志依赖关系

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-logging</artifactId>
  <version>2.1.0.M2</version>
  <scope>compile</scope>
</dependency>

springboot 时候,默认采用此日志门面输出日志。有时候其他框架不一定适用springboot 日志 , 不同的框架底层使用的日志框架也是不尽相同。

# 日志会产生冲突,统一日志输出门面

springboot 默认Slf4j 日志门面,采用日志是Slf4j + logback框架 来进行日志输出

通过查询slf4j 官网可以看到,将其他日志框架转换为slf4j所需要的依赖jar包,也就是中间包

slf4j api 文档 (opens new window)

legacy.png

# 总结

  1. 将系统中其他框架排除出去

例如: spring 默认日志框架是 common-logging 日志框架

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <scope>compile</scope>
  <exclusions>
    <exclusion>
      <artifactId>commons-logging</artifactId>
      <groupId>commons-logging</groupId>
    </exclusion>
  </exclusions>
</dependency>
  1. 用中间包将日志进行替换

springboot默认已经导入jar依赖

导入slf4j其他的实现即可

根据自己选择导入日志依赖(一般默认用logback即可),根据自己喜好