<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="3 seconds">
    <!-- 控制台调试输出 -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符 -->
            <pattern>invoker-info-%d{yyyy-MM-dd HH:mm:ss.SSS} [TraceId:%X{X-B3-TraceId:-} SpanId:%X{X-B3-SpanId:-} ParentSpanId:%X{X-B3-ParentSpanId:-}] [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
        <!--日志级别过滤-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
    </appender>

    <!-- INFO级别日志 -->
    <appender name="info_apd" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名 -->
            <FileNamePattern>logs/info/book-info-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>15</MaxHistory>
            <!--日志文件最大的大小 -->
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 50MB -->
                <maxFileSize>20MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>

        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [TraceId:%X{X-B3-TraceId:-} SpanId:%X{X-B3-SpanId:-} ParentSpanId:%X{X-B3-ParentSpanId:-}] [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
        <!--日志级别过滤-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>

    </appender>

    <!-- WARN级别日志 -->
    <appender name="warn_apd" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名 -->
            <FileNamePattern>logs/warn/book-warn-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>20</MaxHistory>
            <!--日志文件最大的大小 -->
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 50MB -->
                <maxFileSize>20MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>

        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [TraceId:%X{X-B3-TraceId:-} SpanId:%X{X-B3-SpanId:-} ParentSpanId:%X{X-B3-ParentSpanId:-}] [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
        <!--日志级别过滤-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>

    </appender>

    <!-- ERROR级别日志 -->
    <appender name="error_apd" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名 -->
            <FileNamePattern>logs/error/book-error-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>30</MaxHistory>
            <!--日志文件最大的大小 -->
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 50MB -->
                <maxFileSize>20MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>

        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [TraceId:%X{X-B3-TraceId:-} SpanId:%X{X-B3-SpanId:-} ParentSpanId:%X{X-B3-ParentSpanId:-}] [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
        <!--日志级别过滤-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>

    </appender>

    <!-- INFO级别以上的日志全部都输出，不同的级别输出在不同的文件里面 -->
    <root>
        <level value="INFO"/>
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="info_apd"/>
        <appender-ref ref="warn_apd"/>
        <appender-ref ref="error_apd"/>
    </root>

    <logger name="net.sf.ehcache" level="DEBUG"/>
    <logger name="druid.sql" level="DEBUG"/>

</configuration>