Log4j2
- 引入log4j2 依賴械念,spring-boot-starter-log4j2
- 排除Springboot logging
- 針對特別其他的log日志兼容比如logback引入 log4j-1.2-api
- 排除logback
- application.yml 中設(shè)置日志配置文件
build.gradle
dependencies {
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('org.apache.logging.log4j:log4j-1.2-api:'+ log4jAPIVersion)
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
all*.exclude module: 'logback-classic'
all*.exclude module: 'log4j-over-slf4j'
}
application.yml
logging:
config: classpath:log4j2-spring.xml
創(chuàng)建 log4j2-spring.xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<properties>
<property name="PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} |-%-5level [%thread] %c [%L] -| %msg%n</property>
</properties>
<appenders>
<Console name="CONSOLE" target="system_out">
<PatternLayout pattern="${PATTERN}" />
</Console>
</appenders>
<loggers>
<root level="debug">
<appenderref ref="CONSOLE" />
</root>
</loggers>
</configuration>
更多集成參考springboot github
代碼
代碼請移步 Github參考地址
如有疑問請加公眾號(K171),如果覺得對您有幫助請 github start
公眾號_k171