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

    <!-- 关闭时的配置 -->
    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
        <resetJUL>true</resetJUL>
    </contextListener>

    <!-- 禁用关闭钩子 -->
    <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>


    <!-- Info 日志文件 appender （仅在 appName 定义后启用） -->
    <if condition='isDefined("appName")'>
        <then>
            <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <!--                <file>${log.path}/${appName}.log</file>-->
                <encoder>
                    <charset>UTF-8</charset>
                    <pattern>${log.pattern}</pattern>
                </encoder>
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${log.path}/${appName}.log.%d{yyyy-MM-dd}.log</fileNamePattern>
                    <maxHistory>30</maxHistory>
                </rollingPolicy>
            </appender>
        </then>
    </if>

    <!-- Error 日志文件 appender （仅在 appName 定义后启用） -->
    <if condition='isDefined("appName")'>
        <then>
            <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <!--日志文件输出的文件名-->
                    <fileNamePattern>${log.path}/${appName}.error.log.%d{yyyy-MM-dd}.log</fileNamePattern>
                    <!--日志文件保留天数-->
                    <MaxHistory>30</MaxHistory>
                </rollingPolicy>
                <!-- 所有error日志都在这里-->
                <filter class="ch.qos.logback.classic.filter.LevelFilter">
                    <level>ERROR</level>
                    <onMatch>ACCEPT</onMatch>
                    <onMismatch>DENY</onMismatch>
                </filter>
                <encoder>
                    <!-- 格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符 -->
                    <pattern>${log.pattern}</pattern>
                    <!-- 记录日志的编码 -->
                    <charset>UTF-8</charset> <!-- 此处设置字符集 -->
                    <!--                    <immediateFlush>true</immediateFlush>-->
                </encoder>
            </appender>
        </then>
    </if>

    <logger name="com.hr" level="info" />
    <logger name="com.ruoyi" level="info" />
    <logger name="com.yy.basedevelop.common.config" level="info" />
    <logger name="org.springframework" level="info" />

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

</configuration>