欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

logback配置文件

程序员文章站 2022-07-03 20:07:37
...
<?xml version="1.0" encoding="UTF-8" ?>

<configuration>

    <property name="LOG_HOME" value="/home" />
    <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>
                %d - | %msg%n
            </pattern>
        </layout>
    </appender>

    <appender name="fileInfoLog"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <!-- 符合的禁止掉 不写入日志  DENY :禁止  ACCERT:接受  NEUTRAL:中立 (忽略下行)-->
            <onMatch>DENY</onMatch>
            <!-- 不符合的接受 写入日志-->
            <onMismatch>ACCEPT</onMismatch>
        </filter>
        <encoder>
            <pattern>
                %d - | %msg%n
            </pattern>
        </encoder>
        <!--滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--路径 -->
              <FileNamePattern>./logs/info.log.%d{yyyy-MM-dd}.log</FileNamePattern> 
            <!--日志文件保留天数-->
            <MaxHistory>10</MaxHistory>
        </rollingPolicy>
    </appender>


    <appender name="fileErrorLog"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- 过滤  (根据配置的范围过滤)-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!-- 只输出error的日志 -->
            <level>ERROR</level>
        </filter>
        <encoder>
            <pattern>
                %d - | %msg%n
            </pattern>
        </encoder>
        <!--滚动策略 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--路径 -->
              <FileNamePattern>./logs/error.log.%d{yyyy-MM-dd}.log</FileNamePattern> 
            <!--日志文件保留天数-->
            <MaxHistory>10</MaxHistory>
        </rollingPolicy>
    </appender>

    <root level="info">
        <appender-ref ref="consoleLog" />
        <appender-ref ref="fileInfoLog" />
        <appender-ref ref="fileErrorLog" />
    </root>

</configuration>
相关标签: java 日志