<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="appName" value="order-center-tool-2"/>
    <!--引入springboot的默认日志配置-->
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>

    <!-- 日志输出转换器，%idx 输出未被格式化前的日志数据，以及被加入的索引的数据 -->
    <conversionRule conversionWord="idx"  converterClass="com.zm.order.common.log.IndexTextConverter" />
    <conversionRule conversionWord="logLength"  converterClass="com.zm.order.common.log.LogLengthConverter" />

    <appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>logs/file.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>logs/file.%i.log.gz</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>1</maxIndex>
        </rollingPolicy>
        ​

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>200MB</maxFileSize>
        </triggeringPolicy>

        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <jsonFactoryDecorator class="com.zm.order.tool.server.log.MyJsonFactoryDecorator"/>
            <providers>
                <pattern>
                    <pattern>
                        {
                        "hostname": "${hostName}",
                        "pid": "%thread",
                        "app_name": "${appName}",
                        "qm-trace-id": "%X{qm-trace-id:-null}",
                        "qm-trace-span-id": "%X{qm-trace-span-id:-null}",
                        "qm-trace-store-id": "%X{qm-trace-store-id:-null}",
                        "qm-from": "%X{qm-from:-null}",
                        "qm-from-type": "%X{qm-from-type:-null}",
                        "request_time": "%X{log_request_time:-null}",
                        "request_uri": "%X{log_request_uri:-null}",
                        "resp_code": "%X{log_resp_code:-null}",
                        "resp_message": "%X{log_response_message:-null}",
                        "message": "%m",
                        "context": "%ex",
                        "level": null,
                        "level_name": "%level",
                        "channel": null,
                        "datetime": "%date{ISO8601}"
                        }
                    </pattern>
                </pattern>
            </providers>
        </encoder>
    </appender>

    <!-- 异步输出 -->
    <appender name="ROLLING_FILE_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
        <!--默认为 false，在队列满的时候 appender 会阻塞而不是丢弃信息。设置为 true，appender 不会阻塞你的应用而会将消息丢弃-->
        <neverBlock>true</neverBlock>
        <!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
        <discardingThreshold>1638</discardingThreshold>
        <!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
        <queueSize>2048</queueSize>
        <!-- 添加附加的appender,最多只能添加一个 -->
        <appender-ref ref="ROLLING_FILE"/>
    </appender>


    <!-- 控制台输出日志级别 -->

    <root level="info">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="ROLLING_FILE_ASYNC"/>
    </root>

</configuration>