springboot更换日志系统

背景:springboot.2.1.2默认使用logback作为日志系统,我想禁用logback,换成效率更高的log4j2。

一、去除默认的logback依赖

1. 方法一

精准去除

dependencies {
  // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
  compile (group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.2.RELEASE'){
  exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
  }
  testCompile group: 'junit', name: 'junit', version: '4.12'
}

2. 方法二

通过全局配置入口

configurations {
  // remove default logger
  all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'  //IntelliJ会WARNING,忽略这个警告
}

 

二、添加log4j2的日志系统

在dependencies {}中添加依赖即可。

compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '2.1.2.RELEASE'

三、指定配置文件

在application.yaml中设置配置文件路径

logging:
  config: classpath:log4j2.xml

 

posted @ 2019-03-01 19:48  一沙世界  阅读(639)  评论(0编辑  收藏  举报