<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <jmxConfigurator/>
    <property name="LOG_PATH" value="logs"/>
    <property name="APPLICATION" value="jay-monitor-data-server"/>


    <appender name="info-log" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_PATH}/${APPLICATION}.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/%d{yyyyMMdd}/${APPLICATION}-%d{yyyyMMdd}-%i.log</fileNamePattern>
            <maxHistory>30</maxHistory>
            <totalSizeCap>30GB</totalSizeCap>
            <maxFileSize>100MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - [%file:%line] - %msg%n</pattern>
        </encoder>
    </appender>
    <!--    <appender name="cat" class="com.elab.log.log4j.CatLogbackLog">-->
    <!--        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
    <!--            <level>DEBUG</level> &lt;!&ndash; 日志过滤级别 &ndash;&gt;-->
    <!--        </filter>-->
    <!--    </appender>-->


    <appender name="ERROR_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- 过滤日志 -->
        <File>${LOG_PATH}/${APPLICATION}-error.log</File>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
        <!-- 滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/error/%d{yyyyMMdd}/${APPLICATION}-%d{yyyyMMdd}-%i.log</fileNamePattern>
            <maxHistory>30</maxHistory>
            <totalSizeCap>30GB</totalSizeCap>
            <maxFileSize>100MB</maxFileSize>
        </rollingPolicy>
    </appender>

    <!-- 通过异步来提升写入效率 -->
    <appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender">
        <discardingThreshold>0</discardingThreshold>
        <queueSize>10000</queueSize>
        <appender-ref ref="info-log"/>
        <neverBlock>true</neverBlock>
    </appender>

    <!--控制台日志输出配置-->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
             <level>ERROR</level>
         </filter>-->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <encoder charset="UTF-8">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="com.jay.monitor.data.server" level="INFO" additivity="false">
        <appender-ref ref="stdout"/>
    </logger>

    <root level="INFO">
        <!--        <appender-ref ref="console"></appender-ref>-->
        <appender-ref ref="ASYNC_FILE"></appender-ref>
        <appender-ref ref="ERROR_LOG"></appender-ref>
    </root>
</configuration>