<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!--设置日志目录-->
    <property name="LOG_HOME" value="./logs/%d{yyyy-MM-dd}"/>
    <!--这里需要将value改成项目名称-->
    <property name="LOG_NAME" value="psychological"/>
    <!--控制台日志格式-->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <!-- 彩色日志 -->
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{35}) |  %msg %n</pattern>
        </layout>
    </appender>
    <!-- 文件日志策略：每天生成一个日志文件，保存30天的日志文件-->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/${LOG_NAME}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern>　
        </encoder>
    </appender>
    <!-- 文件日志策略：每天生成多个日志文件-->
    <!-- <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${LOG_HOME}/${LOG_NAME}.log</file>
         <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">　　　　　　
             <fileNamePattern>${LOG_HOME}/${LOG_NAME}.%d{yyyy-MM-dd}.%i.zip</fileNamePattern>　　
             <minIndex>1</minIndex>
             <maxIndex>1000</maxIndex>
         </rollingPolicy>
         <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">　　　　　　　
             <maxFileSize>100MB</maxFileSize>　　
         </triggeringPolicy>　　
         <encoder>　　　　
             <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern>　　
         </encoder>
     </appender>-->

    <!-- 【实时位置同步】文件日志策略：每天生成一个日志文件，保存30天的日志文件-->
    <appender name="POSITION_LOG_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/${LOG_NAME}-position-sync.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <!--仅输出INFO日志-->
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- 接收INFO级别和高于INFO级别的日志-->
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern>　
        </encoder>
    </appender>

    <!-- 【用户事件同步】文件日志策略：每天生成一个日志文件，保存30天的日志文件-->
    <appender name="EVENT_LOG_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/${LOG_NAME}-event-sync.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <!--仅输出INFO日志-->
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- 接收INFO级别和高于INFO级别的日志-->
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern>　
        </encoder>
    </appender>

    <!-- 【用户轨迹同步】件日志策略：每天生成一个日志文件，保存30天的日志文件-->
    <appender name="TRACK_LOG_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/${LOG_NAME}-track-sync.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <!--仅输出INFO日志-->
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- 接收INFO级别和高于INFO级别的日志-->
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern>　
        </encoder>
    </appender>

    <!-- 【事件附件同步】文件日志策略：每天生成一个日志文件，保存30天的日志文件-->
    <appender name="FILE_LOG_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/${LOG_NAME}-file-sync.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <!--仅输出INFO日志-->
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- 接收INFO级别和高于INFO级别的日志-->
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern>　
        </encoder>
    </appender>

    <!-- 【系统重启服务】文件日志策略：每天生成一个日志文件，保存30天的日志文件-->
    <appender name="RESTART_LOG_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/${LOG_NAME}-restart.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <!--仅输出INFO日志-->
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- 接收INFO级别和高于INFO级别的日志-->
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern>　
        </encoder>
    </appender>

    <!-- 【REDIS服务】文件日志策略：每天生成一个日志文件，保存30天的日志文件-->
    <appender name="REDIS_LOG_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/${LOG_NAME}-redis.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <!--仅输出INFO日志-->
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- 接收INFO级别和高于INFO级别的日志-->
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} | %msg%n</pattern>　
        </encoder>
    </appender>

    <!--默认日志级别,大小写无关：TRACE, DEBUG, INFO, WARN, ERROR, ALL和OFF-->
    <root level="info">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>
    <!--特定日志级别,其中xxx为项目名称-->
    <logger name="com.patrol.mobile.controller" level="info" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>

    <!--业务操作日志-->
    <logger name="POSITION_LOG" level="info" additivity="false">
        <appender-ref ref="POSITION_LOG_APPENDER"/>
    </logger>
    <logger name="EVENT_LOG" level="info" additivity="false">
        <appender-ref ref="EVENT_LOG_APPENDER"/>
    </logger>
    <logger name="TRACK_LOG" level="info" additivity="false">
        <appender-ref ref="TRACK_LOG_APPENDER"/>
    </logger>
    <logger name="FILE_LOG" level="info" additivity="false">
        <appender-ref ref="FILE_LOG_APPENDER"/>
    </logger>
    <logger name="RESTART_LOG" level="info" additivity="false">
        <appender-ref ref="RESTART_LOG_APPENDER"/>
    </logger>
    <logger name="REDIS_LOG" level="info" additivity="false">
        <appender-ref ref="REDIS_LOG_APPENDER"/>
    </logger>
</configuration>
