<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <springProperty name="spring.application.name" source="spring.application.name"/>
    <property name="LOG_LEVEL_PATTERN"
              value="%5p [${spring.application.name:-},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]"/>
    <property name="FILE_LOG_PATTERN"
              value="${FILE_LOG_PATTERN:-%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} --- [%thread] [%file:%line] %logger - %msg%n}"/>
    <!-- 这个为elk的日志格式-->
    <property name="LOG_STASH_PATTERN"
              value="%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} [%-10X{TRACING_ID}] --- [%thread] [%file:%line] %logger - %msg%n "
    />
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/home/quant_group/asset-distribution/logs/asset-distribution.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>
                /home/quant_group/asset-distribution/logs/asset-distribution.log.%d{yyyy-MM-dd}
            </fileNamePattern>
            <maxHistory>7</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>${FILE_LOG_PATTERN}</pattern>
        </encoder>
    </appender>

    <!-- logstash -->
    <!--这个是logstash的appender-->
    <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <!--配置logStash 服务地址-->
        <destination>172.30.220.6:5044</destination>
        <!-- 日志输出编码 -->
        <encoder charset="UTF-8"
                 class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <timestamp>
                    <timeZone>UTC</timeZone>
                </timestamp>
                <pattern>
                    <pattern>
                        {
                        "type":"${spring.application.name}",
                        "message": "${LOG_STASH_PATTERN}"
                        }
                    </pattern>
                </pattern>
            </providers>
        </encoder>
    </appender>

    <logger name="com.atomikos" level="warn"/>
    <logger name="org.springframework" level="warn"/>
    <logger name="org.mybatis" level="warn"/>
    <logger name="org.apache" level="warn"/>
    <logger name="ch.qos.logback" level="warn"/>
    <logger name="org.apache.kafka.clients" level="error"/>

    <root level="info">
        <appender-ref ref="FILE"/>
        <appender-ref ref="LOGSTASH"/>
    </root>

</configuration>