<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <!-- <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
         <layout class="ch.qos.logback.classic.PatternLayout">
             <pattern>
                 - %msg%n
             </pattern>
         </layout>
     </appender>-->

    <springProperty scope="context" name="loggerLevel1" source="logger.level1"/>
    <springProperty scope="context" name="loggerPath1" source="logger.dir1"/>
    <springProperty scope="context" name="loggerLevel2" source="logger.level2"/>
    <springProperty scope="context" name="loggerPath2" source="logger.dir2"/>
    <property name="pattern" value="%date %level [%thread] %logger{36} [%file : %line] %msg%n"></property>
    <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <!--匹配就舍去-->
            <onMatch>DENY</onMatch>
            <onMismatch>ACCEPT</onMismatch>
        </filter>
        <encoder>
            <pattern>
                ${pattern}
            </pattern>

        </encoder>
        <!--滚动策略-->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--路径-->
            <fileNamePattern>${loggerPath2}/logfile.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <encoder>
            <pattern>
                ${pattern}
            </pattern>

        </encoder>
        <!--滚动策略-->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--路径-->
            <fileNamePattern>${loggerPath1}/logfile.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${pattern}</pattern>
        </encoder>
    </appender>

    <springProfile name="dev">
        <root level="INFO">
            <appender-ref ref="STDOUT"/>
        </root>

    </springProfile>

    <springProfile name="test">
        <root level="WARN">
            <appender-ref ref="fileInfoLog"/>
            <appender-ref ref="fileErrorLog"/>
        </root>
    </springProfile>

    <springProfile name="production">
        <root level="WARN">
            <appender-ref ref="fileInfoLog"/>
            <appender-ref ref="fileErrorLog"/>
        </root>
    </springProfile>
</configuration>