SpringBoot整合日志
一、引入依赖
二、配置 application.yml
三、配置文件 logback.xml
四、配置文件 WebConfigurerAdapter
五、配置常量文件
六、配置拦截器
七、效果展示
一、引入依赖
< dependency>
< groupId> org.springframework.boot</ groupId>
< artifactId> spring-boot-starter-logging</ artifactId>
</ dependency>
二、配置 application.yml
logging :
level :
org.example : debug
org.springframework : warn
springfox : error
org :
springframework :
boot :
autoconfigure : info
config : classpath: logback.xml
三、配置文件 logback.xml
<?xml version="1.0" encoding="UTF-8"?>
< configuration>
< property name = " log.path" value = " /opt/app/youProjectName/log" />
< property name = " log.pattern"
value = " [%-5p-%X{TRACE_ID}] %d{yyyy-MM-dd HH:mm:ss.SSS} %logger{20}-[%method,%line]-%msg%n" />
< appender name = " console" class = " ch.qos.logback.core.ConsoleAppender" >
< encoder>
< pattern> ${log.pattern}</ pattern>
</ encoder>
</ appender>
< appender name = " file_info" class = " ch.qos.logback.core.rolling.RollingFileAppender" >
< file> ${log.path}/sys-info.log</ file>
< rollingPolicy class = " ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
< fileNamePattern> ${log.path}/sys-info.%d{yyyy-MM-dd}.log</ fileNamePattern>
< maxHistory> 60</ maxHistory>
</ rollingPolicy>
< encoder>
< pattern> ${log.pattern}</ pattern>
</ encoder>
< filter class = " ch.qos.logback.classic.filter.LevelFilter" >
< level> INFO</ level>
< onMatch> ACCEPT</ onMatch>
< onMismatch> DENY</ onMismatch>
</ fil