相当美观实用的日志配置(SpringBoot)
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="1000 seconds">
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
<springProperty scope="context" name="spring.application.name" source="spring.application.name" defaultValue="app"/>
<timestamp key="date" datePattern="yyyyMMdd"/>
<property name="colorfulPattern"
value="%blue(%d{MM-dd HH:mm:ss}) [%boldYellow(%thread)] | %highlight(%-5level) | %boldGreen(%logger) %X{clientIp} %X{operateId} - %highlight(%msg) %n"/>
<property name="defaultPattern"
value="%d{MM-dd HH:mm:ss} [%thread] | %-5level | %logger %X{clientIp} %X{operateId} - %msg %n"/>
<property name="log.base_path" value="logs"/>
<property name="log.max.size" value="100MB"/>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${colorfulPattern}</pattern>
</encoder>
</appender>
<appender name="trace.appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.base_path}/${spring.application.name}/trace.${spring.application.name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${log.base_path}/archive/${spring.application.name}/trace.${spring.application.name}.%d{yyyyMMdd}.%i.log.zip
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>${log.max.size}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>${defaultPattern}</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>TRACE</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="info.appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.base_path}/${spring.application.name}/info.${spring.application.name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${log.base_path}/archive/${spring.application.name}/info.${spring.application.name}.%d{yyyyMMdd}.%i.log.zip
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>${log.max.size}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>${defaultPattern}</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="debug.appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.base_path}/${spring.application.name}/debug.${spring.application.name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${log.base_path}/archive/${spring.application.name}/debug.${spring.application.name}.%d{yyyyMMdd}.%i.log.zip
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>${log.max.size}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>${defaultPattern}</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="error.appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.base_path}/${spring.application.name}/error.${spring.application.name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${log.base_path}/archive/${spring.application.name}/error.${spring.application.name}.%d{yyyyMMdd}.%i.log.zip
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>${log.max.size}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>${defaultPattern}</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="trace.async" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>256</queueSize>
<includeCallerData>true</includeCallerData>
<appender-ref ref="trace.appender"/>
</appender>
<logger name="cn.felord.common.http.RestBodyAdvice" level="TRACE"/>
<logger name="cn.felord.app.mapper" level="DEBUG"/>
<springProfile name="dev">
<logger name="org.springframework.security" level="TRACE" additivity="false">
<appender-ref ref="stdout"/>
</logger>
<logger name="org.springframework.security.oauth2" level="DEBUG" additivity="false">
<appender-ref ref="stdout"/>
</logger>
<logger name="org.springframework.web" level="TRACE" additivity="false">
<appender-ref ref="stdout"/>
</logger>
</springProfile>
<root level="info">
<appender-ref ref="stdout"/>
<appender-ref ref="info.appender"/>
<appender-ref ref="debug.appender"/>
<appender-ref ref="error.appender"/>
<appender-ref ref="trace.async"/>
</root>
</configuration>