<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false" >
    <!-- 定义日志路径、级别 -->
    <springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
    <property name="LOG_DIR" value="/logs/${spring.application.name}" />
    <property name="LOG_LEVEL" value="info" />
    <!-- 彩色日志格式 -->
    <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
    <!-- 彩色日志依赖的渲染类 -->
    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
    <!-- 打印日志到控制台 -->
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <Target>System.out</Target>
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
    </appender>

    <!-- 打印error日志 -->
    <appender name="E" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Append>true</Append>
        <encoder>
            <pattern>%date [%level] %logger{80} [%file : %line] - %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/${project.artifactId}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <!-- 打印info日志 -->
    <appender name="I" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Append>true</Append>
        <encoder>
            <pattern>%date [%level] %logger{80} [%file : %line] - %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/${project.artifactId}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <!-- 打印Druid监控日志 -->
    <appender name="druidLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Append>true</Append>
        <encoder>
            <pattern>%date [%level] %logger{80} [%file : %line] - %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>Debug</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/${project.artifactId}/druid.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <!-- druid转存监控日志 -->
    <logger name="druid.statLog" additivity="false">
        <appender-ref ref="druidLog"/>
    </logger>

    <!-- 项目日志 -->
    <logger name="cn.wisenergy"/>

    <!-- 日志根 -->
    <root level="${LOG_LEVEL}">
        <appender-ref ref="stdout"/>
        <appender-ref ref="E"/>
        <appender-ref ref="I"/>
    </root>
</configuration>