<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<property name="app.name" value="" />
<contextName>${app.name}</contextName>
<property name="log.home" value="D:/logs/" />
<!-- <Property name="log.pattern" value="[%d] [%-5p] [%t] [%c{3.}] [%l] [_] [%m]%n" /> -->
<property name="log.file.charset" value="UTF-8" />
<property name="log.file.pattern"
value="[%d] [%-5p] [%t] [%-37.37logger{36}] %msg%n" />
<property name="log.console.charset" value="UTF-8" />
<property name="log.console.pattern"
value="%d %highlight(%-5p) %magenta(${PID}) --- [%15.15t] %cyan(%-37.37logger{36}) : %m%n%n" />
<!-- 控制终端输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${log.console.pattern}</pattern>
<charset>${log.console.charset}</charset>
</encoder>
<withJansi>true</withJansi>
</appender>
<!-- 可以写多个日志文件 appender, 然后区分多个模块的日志 -->
<appender name="FILE_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 日志名称 -->
<File>${log.home}${app.name}/info_${app.name}.log</File>
<!-- 过滤器,只记录 info 级别的日志 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!-- 每天生成日志文件,保存30天的日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的文件名:按时间和体积归档 -->
<FileNamePattern>${log.home}${app.name}/%d{MM}/%d{dd}/info_${app.name}_%d{yyyyMMdd}_%i.log.gz</FileNamePattern>
<!-- 日志文件归档大小 -->
<MaxFileSize>100 MB</MaxFileSize>
<!-- 日志文件保留天数 -->
<MaxHistory>99</MaxHistory>
<!-- 单个日志文件最多 100MB, 30天的日志周期,最大不能超过 10GB -->
<TotalSizeCap>10 GB</TotalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出 -->
<pattern>${log.file.pattern}</pattern>
<!-- 编码 -->
<charset>${log.file.charset}</charset>
</encoder>
</appender>
<appender name="FILE_WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log.home}${app.name}/warn_${app.name}.log</File>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>${log.home}${app.name}/%d{MM}/%d{dd}/warn_${app.name}_%d{yyyyMMdd}_%i.log.gz</FileNamePattern>
<MaxFileSize>100 MB</MaxFileSize>
<MaxHistory>99</MaxHistory>
<TotalSizeCap>10 GB</TotalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${log.file.pattern}</pattern>
<charset>${log.file.charset}</charset>
</encoder>
</appender>
<appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${log.home}${app.name}/error_${app.name}.log</File>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<FileNamePattern>${log.home}${app.name}/%d{MM}/%d{dd}/error_${app.name}_%d{yyyyMMdd}_%i.log.gz</FileNamePattern>
<MaxFileSize>100 MB</MaxFileSize>
<MaxHistory>99</MaxHistory>
<TotalSizeCap>10 GB</TotalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${log.file.pattern}</pattern>
<charset>${log.file.charset}</charset>
</encoder>
</appender>
<!-- 生产环境 -->
<springProfile name="prod">
<!-- 配置日志的根节点 -->
<root level="INFO">
<appender-ref ref="FILE_ERROR" />
<appender-ref ref="FILE_WARN" />
<appender-ref ref="FILE_INFO" />
<appender-ref ref="STDOUT" />
</root>
<!-- 第三方日志系统 -->
<logger name="org.springframework.web" level="WARN"/>
<logger name="org.springboot.sample" level="WARN" />
</springProfile>
</configuration>