相当美观实用的日志配置(SpringBoot)

相当美观实用的日志配置(SpringBoot)


<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}.logfile>
        <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>TRACElevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="info.appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.base_path}/${spring.application.name}/info.${spring.application.name}.logfile>
        <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>INFOlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="debug.appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.base_path}/${spring.application.name}/debug.${spring.application.name}.logfile>
        <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>DEBUGlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="error.appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.base_path}/${spring.application.name}/error.${spring.application.name}.logfile>
        <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>ERRORlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>
    
    
    
    <appender name="trace.async" class="ch.qos.logback.classic.AsyncAppender">
        <discardingThreshold>0discardingThreshold>
        <queueSize>256queueSize>
        <includeCallerData>trueincludeCallerData>
        <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>

你可能感兴趣的:(java,数据库,spring)