<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false" >
    <!--为了防止进程退出时，内存中的数据丢失，请加上此选项-->
    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
    <!-- 日志存放路径 -->
    <property name="log.path" value="logs" />
    <!-- 日志输出格式 -->
    <property name="log.pattern" value="%d{HH:mm:ss.SSS} [traceId:%X{traceId}] [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
    <springProperty scope="context" name="appName" source="spring.application.name" />
    <!-- 控制台输出 -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
    </appender>

    <!--    <appender name="aliyun" class="com.aliyun.openservices.log.logback.LoghubAppender">-->


    <!-- 系统日志输出 -->
    <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--        <file>${log.path}/app.log</file>-->
        <!-- 循环政策：基于时间创建日志文件 -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [traceId:%X{traceId}] [%thread] %-5level %logger{20} - [%method,%line] - %msg%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- rollover daily and when the file reaches 100MB -->
            <fileNamePattern>${log.path}/%d{yyyy-MM-dd}/info.%i.log</fileNamePattern>
            <maxFileSize>1MB</maxFileSize>
            <maxHistory>30</maxHistory> <!-- keep 30 days' worth of history -->
            <totalSizeCap>1GB</totalSizeCap> <!-- optional, limit the total size for all archive files -->
        </rollingPolicy>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <!-- 过滤的级别 -->
            <level>INFO</level>
            <!-- 匹配时的操作：接收（记录） -->
            <onMatch>ACCEPT</onMatch>
            <!-- 不匹配时的操作：拒绝（不记录） -->
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--        <file>${log.path}/error.log</file>-->
        <!-- 循环政策：基于时间创建日志文件 -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [traceId:%X{traceId}] [%thread] %-5level %logger{20} - [%method,%line] - %msg%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- rollover daily and when the file reaches 100MB -->
            <fileNamePattern>${log.path}/%d{yyyy-MM-dd}/err.%i.log</fileNamePattern>
            <maxFileSize>1MB</maxFileSize>
            <maxHistory>30</maxHistory> <!-- keep 30 days' worth of history -->
            <totalSizeCap>1GB</totalSizeCap> <!-- optional, limit the total size for all archive files -->
        </rollingPolicy>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <!-- 过滤的级别 -->
            <level>ERROR</level>
            <!-- 匹配时的操作：接收（记录） -->
            <onMatch>ACCEPT</onMatch>
            <!-- 不匹配时的操作：拒绝（不记录） -->
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>


    <!-- 系统模块日志级别控制  -->
    <logger name="com.hr" level="info" />
    <logger name="com.ruoyi" level="info" />
    <logger name="com.yy.basedevelop.common.config" level="info" />


    <!-- Spring日志级别控制  -->
    <logger name="org.springframework" level="info" />

    <root level="info">
        <appender-ref ref="console" />
    </root>

    <!--系统操作日志-->
    <root level="info">

        <appender-ref ref="file_info" />
        <appender-ref ref="file_error" />
    </root>

<!--    <logger name="com.hr" additivity="true">-->
<!--        <appender-ref ref="aliyun"/>-->
<!--    </logger>-->

</configuration>