<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Properties>
        <Property name="log_base_dir">logs/edu-train</Property>
        <Property name="log_pattern">[%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5p][%t][%c.%M:%L] [%X{x-request-trace-id}] %msg%xEx%n</Property>
        <Property name="max_single_file_size">10MB</Property>
    </Properties>

    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="${log_pattern}"/>
        </Console>

        <RollingFile name="INFO" fileName="${log_base_dir}/info.log"
                     filePattern="${log_base_dir}/info_%d{yyyy_MM_dd_HH}_%i.log.gz">
            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${log_pattern}"/>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${max_single_file_size}"/>
            </Policies>
            <DefaultRolloverStrategy max="10">
                <Delete basePath="${log_base_dir}" maxDepth="2">
                    <!-- 最近30天，最多5GB的日志 -->
                    <IfFileName glob="info*.log.gz">
                        <IfAny>
                            <IfLastModified age="10d"/>
                            <IfAccumulatedFileSize exceeds="5GB"/>
                        </IfAny>
                    </IfFileName>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>

        <RollingFile name="ERROR" fileName="${log_base_dir}/error.log"
                     filePattern="${log_base_dir}/info_%d{yyyy_MM_dd_HH}_%i.log.gz">
            <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${log_pattern}"/>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${max_single_file_size}"/>
            </Policies>
            <DefaultRolloverStrategy max="10">
                <Delete basePath="${log_base_dir}" maxDepth="2">
                    <!-- 最近30天，最多5GB的日志 -->
                    <IfFileName glob="error*.log.gz">
                        <IfAny>
                            <IfLastModified age="10d"/>
                            <IfAccumulatedFileSize exceeds="5GB"/>
                        </IfAny>
                    </IfFileName>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>


        <RollingFile name="TIMECOST_JSON" fileName="${log_base_dir}/timeCost.log"
                     filePattern="${log_base_dir}/timeCost_%d{yyyy_MM_dd_HH}_%i.log.gz">
            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${max_single_file_size}"/>
            </Policies>
            <DefaultRolloverStrategy max="10">
                <Delete basePath="${log_base_dir}" maxDepth="2">
                    <!-- 最近30天，最多5GB的日志 -->
                    <IfFileName glob="timeCost*.log.gz">
                        <IfAny>
                            <IfLastModified age="2d"/>
                            <IfAccumulatedFileSize exceeds="2GB"/>
                        </IfAny>
                    </IfFileName>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>
    </Appenders>

    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="CONSOLE"/>
            <AppenderRef ref="INFO"/>
            <AppenderRef ref="ERROR"/>
        </Root>

        <logger name="com.face.util.TimeLogPrintUtils" level="info" additivity ="false">
            <AppenderRef ref="TIMECOST_JSON"/>
        </logger>

        <logger name="com.edu" level="info"  additivity ="false">
            <AppenderRef ref="CONSOLE"/>
            <AppenderRef ref="INFO"/>
            <AppenderRef ref="ERROR"/>
        </logger>
        <logger name="org.springframework" level="info" additivity ="false">
            <AppenderRef ref="CONSOLE"/>
            <AppenderRef ref="INFO"/>
            <AppenderRef ref="ERROR"/>
        </logger>
        <logger name="org.mybatis" level="info"  additivity ="false">
            <AppenderRef ref="CONSOLE"/>
            <AppenderRef ref="INFO"/>
            <AppenderRef ref="ERROR"/>
        </logger>
        <logger name="com.baomidou" level="info"  additivity ="false">
            <AppenderRef ref="CONSOLE"/>
            <AppenderRef ref="INFO"/>
            <AppenderRef ref="ERROR"/>
        </logger>

        <!-- 其他 Logger 配置 -->

        <Logger name="com.baomidou.mybatisplus.core.toolkit" level="debug"  additivity ="false"/>
        <Logger name="com.baomidou.mybatisplus.extension.toolkit" level="debug"  additivity ="false"/>
        <Logger name="org.apache.ibatis" level="debug"  additivity ="false"/>
        <Logger name="com.gitee.Jmysy" level="ERROR"  additivity ="false"/>
        <Logger name="com.github.shyiko" level="ERROR"  additivity ="false"/>
        <Logger name="org.springframework.jdbc" level="ERROR"  additivity ="false"/>
        <Logger name="github.shyiko.mysql" level="ERROR"  additivity ="false"/>
        <Logger name="com.gitee.Jmysy.binlog4j" level="ERROR"  additivity ="false"/>

    </Loggers>
</Configuration>