<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <jmxConfigurator/>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <!-- Example for logging into the build folder of your project -->
    <property name="LOG_FILE" value="log"/>

    <!-- You can override this to have a custom pattern -->
    <property name="CONSOLE_LOG_PATTERN"
              value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} [%X{requestId}] %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}"/>

    <!-- Appender to log to console -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- Minimum logging level to be presented in the console logs-->
            <level>DEBUG</level>
        </filter>
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
    </appender>

    <!-- Appender to log to file -->
    <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_FILE}/info.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_FILE}/info.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
            <!-- 如果按天来回滚，则最大保存时间为5天，5天之前的都将被清理掉 -->
            <maxHistory>5</maxHistory>
            <!-- 日志总保存量为20GB -->
            <totalSizeCap>20GB</totalSizeCap>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!--文件达到 最大1GB时会被压缩和切割 -->
                <maxFileSize>1GB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
    </appender>

    <!-- Appender to log to file only error level log -->
    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_FILE}/error.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_FILE}/error.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
            <!-- 如果按天来回滚，则最大保存时间为5天，5天之前的都将被清理掉 -->
            <maxHistory>5</maxHistory>
            <!-- 日志总保存量为5GB -->
            <totalSizeCap>5GB</totalSizeCap>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!--文件达到 最大1GB时会被压缩和切割 -->
                <maxFileSize>1GB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印错误日志 -->
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <logger name="cc.iotkit" level="debug" additivity="false">
        <appender-ref ref="info"/>
        <appender-ref ref="error"/>
        <appender-ref ref="console"/>
    </logger>

    <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="trace"/>

    <!--    <logger name="org.springframework" level="debug" additivity="false">-->
<!--        <appender-ref ref="info"/>-->
<!--        <appender-ref ref="error"/>-->
<!--        <appender-ref ref="console"/>-->
<!--    </logger>-->

    <root level="INFO">
        <appender-ref ref="info"/>
        <appender-ref ref="error"/>
        <appender-ref ref="console"/>
    </root>

</configuration>