logback-spring.xml 2.9 KB
Newer Older
Q
qinyingjie 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<?xml version="1.0" encoding="UTF-8"?>
<configuration  debug="true">

    <!-- 此xml在spring-boot-1.5.3.RELEASE.jar里 -->
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <!--控制台打印日志,不需要配置appender了-->
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
    <!-- 开启后可以通过jmx动态控制日志级别(springboot Admin的功能) -->
    <!--<jmxConfigurator/>-->

    <!--总日志-->
    <appender name="ALL-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--日志存放路径-->
        <file>../logs/springboot-mybatis.log</file>
        <encoder>
            <!-- pattern节点,用来设置日志的输入格式 -->
            <pattern>%date [%level] [%thread] %logger{60} [%file : %line] %msg%n</pattern>
            <!--文件编码格式-->
            <charset>UTF-8</charset>
        </encoder>
        <!-- 滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 添加.gz 历史日志会启用压缩 大大缩小日志文件所占空间 -->
            <fileNamePattern>../logs/springboot-mybatis.log.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!--  保留30天日志 -->
            <maxHistory>30</maxHistory>
            <!--文件最大存储-->
            <totalSizeCap>10GB</totalSizeCap>
        </rollingPolicy>
    </appender>

    <!--错误日志-->
    <appender name="ERROR-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--日志存放路径-->
        <file>../logs/error.log</file>
        <encoder>
            <pattern>%date [%level] [%thread] %logger{60} [%file : %line] %msg%n</pattern>
            <!--文件编码格式-->
            <charset>UTF-8</charset>
        </encoder>
        <!-- 滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 添加.gz 历史日志会启用压缩 大大缩小日志文件所占空间 -->
            <fileNamePattern>../logs/error.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!--  保留30天日志 -->
            <maxHistory>30</maxHistory>
            <!--文件最大存储-->
            <totalSizeCap>10GB</totalSizeCap>
        </rollingPolicy>
        <!-- 过滤日志 -->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <!-- 用于配置符合过滤条件的操作 -->
            <onMatch>ACCEPT</onMatch>
            <!-- 用于配置不符合过滤条件的操作 -->
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <logger name="com.kwan.springbootkwan" level="INFO"/>

    <root level="INFO">
        <!--控制台打印日志-->
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="ALL-FILE"/>
        <appender-ref ref="ERROR-FILE"/>
    </root>

</configuration>