<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="10" status="WARN">
    <Properties>
        <Property name="APP_NAME">dg_lab</Property>
        <Property name="LOG_HOME">${env:log.dir:-logs}/${APP_NAME}</Property>
        <Property name="ENCODER_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{80} - %msg%n</Property>
    </Properties>

    <Appenders>
        <!-- 控制台输出 -->
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="${ENCODER_PATTERN}" />
        </Console>

        <!-- 普通日志输出 -->
        <RollingFile name="FILE" fileName="${LOG_HOME}/output.log"
                     filePattern="${LOG_HOME}/output.%d{yyyy-MM-dd}.log">
            <PatternLayout pattern="${ENCODER_PATTERN}" />
            <Policies>
                <TimeBasedTriggeringPolicy />
            </Policies>
            <DefaultRolloverStrategy max="7" />
        </RollingFile>

        <!-- 错误日志输出（WARN及以上） -->
        <RollingFile name="ERROR_FILE" fileName="${LOG_HOME}/error.log"
                     filePattern="${LOG_HOME}/error.%d{yyyy-MM-dd}.log">
            <PatternLayout pattern="${ENCODER_PATTERN}" />
            <Filters>
                <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY" />
            </Filters>
            <Policies>
                <TimeBasedTriggeringPolicy />
            </Policies>
            <DefaultRolloverStrategy max="7" />
        </RollingFile>

        <!-- sync日志 -->
        <RollingFile name="SYNC_FILE" fileName="${LOG_HOME}/sync.log"
                     filePattern="${LOG_HOME}/sync.%d{yyyy-MM-dd}.log">
            <PatternLayout pattern="${ENCODER_PATTERN}" />
            <Policies>
                <TimeBasedTriggeringPolicy />
            </Policies>
            <DefaultRolloverStrategy max="7" />
        </RollingFile>
    </Appenders>

    <Loggers>
        <!-- 指定 logger -->
        <Logger name="log.sync" level="debug" additivity="true">
            <AppenderRef ref="SYNC_FILE" />
        </Logger>

        <!-- 根日志记录器 -->
        <Root level="debug">
            <AppenderRef ref="STDOUT" />
            <AppenderRef ref="FILE" />
            <AppenderRef ref="ERROR_FILE" />
        </Root>
    </Loggers>
</Configuration>
