<?xml version="1.0" encoding="UTF-8"?>
        <!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
        <!--Configuration后面的status，这个用于设置log4j2自身内部的信息输出，可以不设置，当设置成trace时，你会看到log4j2内部各种详细输出-->
        <!--monitorInterval：Log4j能够自动检测修改配置 文件和重新配置本身，设置间隔秒数-->
<configuration status="WARN" monitorInterval="30" packages="cn.estsh.impp.framework.boot.log">
<Properties>
    <Property name="log4j2.level" value="INFO"/>
    <!-- 日志存放位置 -->
    <Property name="logFileRootPath" value="../logs"/>

    <!-- 日志输出格式 -->
    <Property name="info_pattern">[%p] %d{yyyy-MM-dd HH:mm:ss-SSS} %c(%M:%L) 信息:%m%n</Property>
    <Property name="file_pattern">[%p] %d{yyyy-MM-dd HH:mm:ss-SSS} %-5level %class{36} %L %M - %msg%xEx%n</Property>
</Properties>

<appenders>
    <!-- impp 日志拦截 -->
    <ImppLog4j2Appender name="impp_log">
        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %t [%c{1.}(%M:%L)] ==>> %msg%xEx"/>
    </ImppLog4j2Appender>

    <!-- 应用日志文件-->
    <RollingRandomAccessFile name="log_file"
                             fileName="${logFileRootPath}/${project.name}.log"
                             append="true" immediateFlush="true" bufferedIO="true" bufferSize="8192"
                             filePattern="${logFileRootPath}/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz">
        <PatternLayout pattern="${file_pattern}"/>

        <Filters>
            <ImppScheduleFilter onMatch="DENY" onMismatch="ACCEPT" />
        </Filters>

        <!-- 滚动策略 -->
        <Policies>
            <TimeBasedTriggeringPolicy/>
            <SizeBasedTriggeringPolicy size="1024 MB"/>
        </Policies>

        <!-- 定时删除 -->
        <DefaultRolloverStrategy>
            <Delete basePath="${logFileRootPath}" maxDepth="2">
                <IfFileName glob="**/${project.name}**.log.gz">
                    <IfLastModified age="7d"/>
                </IfFileName>

                <!-- 兼容未压缩日志的版本，后期可移除 -->
                <IfFileName glob="**/${project.name}**.log">
                    <IfLastModified age="7d"/>
                </IfFileName>
            </Delete>
        </DefaultRolloverStrategy>
    </RollingRandomAccessFile>

    <!-- 应用异常日志文件-->
    <RollingRandomAccessFile name="log_error_file"
                             fileName="${logFileRootPath}/${project.name}-error.log"
                             append="true" immediateFlush="true" bufferedIO="true" bufferSize="8192"
                             filePattern="${logFileRootPath}/$${date:yyyy-MM}/${project.name}-error-%d{yyyy-MM-dd}-%i.log.gz">
        <PatternLayout pattern="${file_pattern}"/>

        <ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/>

        <!-- 滚动策略 -->
        <Policies>
            <TimeBasedTriggeringPolicy/>
            <SizeBasedTriggeringPolicy size="1024 MB"/>
        </Policies>

        <!-- 定时删除 -->
        <DefaultRolloverStrategy>
            <Delete basePath="${logFileRootPath}" maxDepth="2">
                <IfFileName glob="**/${project.name}-error**.log.gz">
                    <IfLastModified age="7d"/>
                </IfFileName>

                <!-- 兼容未压缩日志的版本，后期可移除 -->
                <IfFileName glob="**/${project.name}-error**.log">
                    <IfLastModified age="7d"/>
                </IfFileName>
            </Delete>
        </DefaultRolloverStrategy>
    </RollingRandomAccessFile>

    <!-- 应用调度日志文件-->
    <ImppLog4j2File name="log_schedule_file"
                    filePath="${logFileRootPath}/schedule/"
                    append="true" immediateFlush="true" bufferedIO="true" bufferSize="8192"
                    filePattern="${logFileRootPath}/schedule/$${date:yyyy-MM}/task-name-%d{yyyy-MM-dd}-%i.log.gz">
        <PatternLayout pattern="${file_pattern}"/>

        <Filters>
            <ImppScheduleFilter onMatch="ACCEPT" onMismatch="DENY"/>
        </Filters>

        <!-- 滚动策略 -->
        <Policies>
            <TimeBasedTriggeringPolicy/>
            <SizeBasedTriggeringPolicy size="1024 MB"/>
        </Policies>

        <!-- 定时删除 -->
        <DefaultRolloverStrategy>
            <Delete basePath="${logFileRootPath}" maxDepth="2">
                <IfFileName glob="**/schedule/**.log.gz">
                    <IfLastModified age="7d"/>
                </IfFileName>

                <!-- 兼容未压缩日志的版本，后期可移除 -->
                <IfFileName glob="**/schedule/**.log">
                    <IfLastModified age="7d"/>
                </IfFileName>
            </Delete>
        </DefaultRolloverStrategy>
    </ImppLog4j2File>

    <!--控制台日志-->
    <console name="console" target="SYSTEM_OUT" follow="true">
        <PatternLayout>
            <Pattern>${info_pattern}</Pattern>
        </PatternLayout>
    </console>
</appenders>

<loggers>
    <!-- 忽略 Swagger 格式化错误 -->
    <logger name="io.swagger.models.parameters.AbstractSerializableParameter" level="ERROR"/>
    <root level="${log4j2.level}">
        <appender-ref ref="impp_log"/>
        <appender-ref ref="console"/>
        <appender-ref ref="log_schedule_file"/>
        <appender-ref ref="log_file"/>
        <appender-ref ref="log_error_file"/>
    </root>
</loggers>
</configuration>