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

    <property resource="commons.properties"/>
    <property file="/opt/cordys/conf/cordys-crm.properties" ignoreResourceNotFound="true"/>

    <!-- Console 输出 -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d %5p %40.40c:%4L - %m%n</pattern>
        </encoder>
    </appender>

    <!-- ===================== 文件 Appender ===================== -->

    <appender name="traceAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>TRACE</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <File>${logging.file.path}/trace.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${logging.file.path}/history/trace.%d{yyyyMMdd}-%i.log</FileNamePattern>
            <maxHistory>${logger.max.history:-30}</maxHistory>
            <maxFileSize>50MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
        </encoder>
    </appender>

    <appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <File>${logging.file.path}/debug.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${logging.file.path}/history/debug.%d{yyyyMMdd}-%i.log</FileNamePattern>
            <maxHistory>${logger.max.history:-30}</maxHistory>
            <maxFileSize>50MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
        </encoder>
    </appender>

    <appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <File>${logging.file.path}/info.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${logging.file.path}/history/info.%d{yyyyMMdd}-%i.log</FileNamePattern>
            <maxHistory>${logger.max.history:-30}</maxHistory>
            <maxFileSize>50MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
        </encoder>
    </appender>

    <appender name="warnAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARN</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <File>${logging.file.path}/warn.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${logging.file.path}/history/warn.%d{yyyyMMdd}-%i.log</FileNamePattern>
            <maxHistory>${logger.max.history:-30}</maxHistory>
            <maxFileSize>50MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
        </encoder>
    </appender>

    <appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <File>${logging.file.path}/error.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${logging.file.path}/history/error.%d{yyyyMMdd}-%i.log</FileNamePattern>
            <maxHistory>${logger.max.history:-30}</maxHistory>
            <maxFileSize>50MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</Pattern>
        </encoder>
    </appender>

    <!-- ===================== Async Appender ===================== -->

    <appender name="traceAsyncAppender" class="ch.qos.logback.classic.AsyncAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>TRACE</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <queueSize>10000</queueSize>
        <appender-ref ref="traceAppender"/>
    </appender>

    <appender name="debugAsyncAppender" class="ch.qos.logback.classic.AsyncAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <queueSize>10000</queueSize>
        <appender-ref ref="debugAppender"/>
    </appender>

    <appender name="infoAsyncAppender" class="ch.qos.logback.classic.AsyncAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <queueSize>10000</queueSize>
        <appender-ref ref="infoAppender"/>
    </appender>

    <appender name="warnAsyncAppender" class="ch.qos.logback.classic.AsyncAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARN</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <queueSize>10000</queueSize>
        <includeCallerData>true</includeCallerData>
        <appender-ref ref="warnAppender"/>
    </appender>

    <appender name="errorAsyncAppender" class="ch.qos.logback.classic.AsyncAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <queueSize>10000</queueSize>
        <includeCallerData>true</includeCallerData>
        <appender-ref ref="errorAppender"/>
    </appender>

    <!-- ===================== Logger ===================== -->

    <!-- cn.cordys 模块日志 -->
    <logger name="cn.cordys" additivity="false" level="${logback.level:INFO}">
        <appender-ref ref="traceAsyncAppender"/>
        <appender-ref ref="debugAsyncAppender"/>
        <appender-ref ref="infoAsyncAppender"/>
        <appender-ref ref="warnAsyncAppender"/>
        <appender-ref ref="errorAsyncAppender"/>
        <appender-ref ref="console"/>
    </logger>

    <!-- cn.cordys.Application 单独 INFO 输出 -->
    <logger name="cn.cordys.Application" additivity="false" level="${logback.level:INFO}">
        <appender-ref ref="infoAsyncAppender"/>
    </logger>

    <!-- 容器日志 -->
    <logger name="org.eclipse.jetty.ee10.servlet.ServletChannel" level="ERROR"/>

    <!-- ===================== Root ===================== -->
    <root level="INFO">
        <appender-ref ref="console"/>
    </root>

</configuration>
