<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <property name="LOG_PATH" value="Charts"/>
    <property name="application-name" value="${HOSTNAME}" />
    <property name="LOG_LEVEL" value="${LOG_LEVEL}" />
    <property name="APP_NAME" value="xisc-pm" />
    <property name="LOG_PATTERN"
              value="%d{yyyy-MM-dd HH:mm:ss.SSS}|THREAD-${PID}-%thread|%-5level|${APP_NAME}|TRACE-%X{traceId}|TENANT-%X{tenantId}|USER-%X{userId}|API-%X{apiName}|%-40.40logger{39}: %msg%n"/>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder >
            <pattern>${LOG_PATTERN}</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <!--默认文件-->
    <appender name="file-default"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/${application-name}-default.log</file>
        <prudent>true</prudent>
        <Append>true</Append>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>${LOG_LEVEL}</level>
        </filter>
        <encoder>
            <pattern>${LOG_PATTERN}</pattern>
            <charset>UTF-8</charset>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/${application-name}-default.%d{yyyy-MM-dd.HH}-%i.log</fileNamePattern>
            <MaxHistory>120</MaxHistory>
            <!--日志文件最大的大小-->
            <maxFileSize>100MB</maxFileSize>
            <!--该滚动策略日志的总大小，超过的日志会被清除-->
            <totalSizeCap>500MB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
    </appender>

    <!--错误以及以上级别日志-->
    <appender name="file-error"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/${application-name}-error.log</file>
        <prudent>true</prudent>
        <Append>true</Append>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <encoder>
            <pattern>${LOG_PATTERN}</pattern>
            <charset>UTF-8</charset>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_PATH}/${application-name}-error.%d{yyyy-MM-dd}.log</FileNamePattern>
            <MaxHistory>120</MaxHistory>
            <!--该滚动策略日志的总大小，超过的日志会被清除-->
            <totalSizeCap>1000MB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
    </appender>

    <root level="info">
        <appender-ref ref="file-default"/>
        <appender-ref ref="file-error"/>
        <appender-ref ref="console"/>
    </root>

</configuration>
