logback.xml 基本配置

前端之家收集整理的这篇文章主要介绍了logback.xml 基本配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

注:个人学习笔记,不保证正确性

<?xml version="1.0" encoding="UTF-8"?>
<!--更多配置请参考http://logback.qos.ch/manual/filters.html--> <configuration>
    <!--定义变量-->  <property name="log.home2" value="home/logs" />
    <!--可以使用配置文件定义变量-->  <property file="logback.properties"/>
    <!--控制台打印-->  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder charset="utf-8"> <!-- encoder 可以指定字符集,对于中文输出有意义 -->  <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%n</pattern>
        </encoder>
    </appender>
    <!--定义一个info级别的appender-->  <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">

        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
            <!--过滤掉非info级别的日志-->  <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
                <expression>
                    e.level.toInt() == INFO.toInt()
                </expression>
            </evaluator>
            <OnMismatch>DENY</OnMismatch>
            <OnMatch>NEUTRAL</OnMatch>
        </filter>
        <!-- 可让每天产生一个日志文件,最多 2 个,自动回滚 -->  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.home}/logback-info.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <encoder charset="utf-8">
            <!--line表示打印行号-->  <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%n</pattern>
        </encoder>
    </appender>

    <!--定义一个error级别的appender-->  <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- deny all events with a level below INFO,that is TRACE,DEBUG and INFO -->  <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
        <!-- 可让每天产生一个日志文件,最多 2 个,自动回滚 -->  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.home}/logback-error.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%n</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <!--additivity标示是否还想其他append(如root配置)里面追加日志-->  <logger name="com.jing" level="debug" additivity="${log.additivity}">
        <appender-ref ref="info"/>
        <appender-ref ref="error"/>
    </logger>

    <root>
        <level value="${root.level}"/>
        <appender-ref ref="console"/>
    </root>
</configuration>
原文链接:https://www.f2er.com/xml/294497.html

猜你在找的XML相关文章