<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--    <include resource="org/springframework/boot/logging/logback/base.xml"/>-->
    <!--
    官方文档指明，需要使用<springProperty>,才可使用application.properties（或application.yml）中的值
    -->
    <springProperty scope="context" name="loggerLevel" source="logger.level"/>
    <springProperty scope="context" name="loggerPath" source="logger.dir"/>
    <property name="pattern" value="%date %level [%thread] %logger{36} [%file : %line] %msg%n"></property>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${pattern}</pattern>
        </encoder>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${loggerPath}/log/logfile.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${loggerPath}/log/logfile.%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>${pattern}</pattern>
        </encoder>
    </appender>
    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <file>${loggerPath}/error/logfile.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${loggerPath}/error/logfile.%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>${pattern}</pattern>
        </encoder>
    </appender>
    <appender name="HK" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${loggerPath}/hk/logfile.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${loggerPath}/hk/%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%date %level [%file : %line] %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="DW_STD" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date %level [%file : %line] %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="DW_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${loggerPath}/watch/logfile.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${loggerPath}/watch/%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>30</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%date %level [%file : %line] %msg%n</pattern>
        </encoder>
    </appender>
    <!--
    直接用maven的变量是@...@,用spring的变量是${...}
    -->
    <springProfile name="dev">
        <root level="INFO">
            <appender-ref ref="STDOUT"/>
        </root>
        <!--root的level不能用变量-->
        <logger name="jdbc" level="WARN" additivity="false">
            <appender-ref ref="STDOUT" />
        </logger>
        <logger name="jdbc.sqltiming" level="ON" additivity="false">
            <appender-ref ref="STDOUT" />
        </logger>
        <logger name="com.jpsoft" level="${loggerLevel}" additivity="false" >
            <appender-ref ref="STDOUT" />
        </logger>
        <logger name="com.jpsoft.shinestar.healthwatch" level="${loggerLevel}" additivity="false" >
            <appender-ref ref="DW_STD" />
        </logger>
    </springProfile>
    <springProfile name="test">
        <root level="WARN">
            <appender-ref ref="STDOUT" />
            <appender-ref ref="FILE" />
            <appender-ref ref="ERROR_FILE" />
        </root>
        <logger name="com.jpsoft.ehome" level="${loggerLevel}" additivity="false" >
            <appender-ref ref="HK" />
        </logger>
        <logger name="com.jpsoft.shinestar.healthwatch" level="${loggerLevel}" additivity="false" >
            <appender-ref ref="DW_FILE" />
        </logger>
    </springProfile>
    <springProfile name="production">
        <root level="WARN">
            <appender-ref ref="STDOUT" />
            <appender-ref ref="FILE" />
            <appender-ref ref="ERROR_FILE" />
        </root>
        <logger name="com.jpsoft.ehome" level="${loggerLevel}" additivity="false" >
            <appender-ref ref="HK" />
        </logger>
        <logger name="com.jpsoft.shinestar.healthwatch" level="${loggerLevel}" additivity="false" >
            <appender-ref ref="DW_FILE" />
        </logger>
        <logger name="com.jpsoft" level="${loggerLevel}" additivity="false" >
            <appender-ref ref="FILE" />
        </logger>
    </springProfile>
</configuration>