<?xml version="1.0" encoding="UTF-8"?>

<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
    <!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
    <!--定义日志文件的存储地址和前缀名-->
    <property name="LOG_HOME" value="./logs"/>
    <property name="LOG_PREFIX" value="Cpop-Mall"/>

    <!--控制台输出 -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder charset="UTF-8">
            <!--格式化输出：%d表示日期，%-5level：级别，%thread表示线程名，%file输出文件名，%line文件行数，%msg：日志消息，%n是换行符-->
            <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %level [%thread] %file:%line - %msg%n</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <springProfile name="test,prod">
        <appender name="SYS_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <File>${LOG_HOME}/${LOG_PREFIX}-info.log</File>
            <append>true</append>
            <!--过滤器,只打INFO级别的日志-->
            <filter class="ch.qos.logback.classic.filter.LevelFilter">
                <level>INFO</level>
                <onMatch>ACCEPT</onMatch>
                <onMismatch>DENY</onMismatch>
            </filter>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%d</fileNamePattern>
                <maxHistory>7</maxHistory>
            </rollingPolicy>
            <encoder charset="UTF-8">
                <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %level [%thread] %file:%line - %msg%n</pattern>
                <charset>UTF-8</charset>
            </encoder>
        </appender>

        <appender name="SYS_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <File>${LOG_HOME}/${LOG_PREFIX}-error.log</File>
            <append>true</append>
            <!--过滤器,只打ERROR级别的日志-->
            <filter class="ch.qos.logback.classic.filter.LevelFilter">
                <level>ERROR</level>
                <onMatch>ACCEPT</onMatch>
                <onMismatch>DENY</onMismatch>
            </filter>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%d</fileNamePattern>
                <maxHistory>7</maxHistory>
            </rollingPolicy>
            <encoder charset="UTF-8">
                <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %level [%thread] %file:%line - %msg%n</pattern>
                <charset>UTF-8</charset>
            </encoder>
        </appender>
    </springProfile>

    <!--info和error分开打印-->
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
        <springProfile name="test,prod">
            <appender-ref ref="SYS_INFO"/>
            <appender-ref ref="SYS_ERROR"/>
        </springProfile>
    </root>
    <logger name="com.cpop.mall" level="DEBUG"/>
</configuration>
