logback.xml 基本配置

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

xml version="1.0" encoding="UTF-8"?>

<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"> 
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%npattern>
        encoder>
    appender>
    
    <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">

        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
            
            <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
                <expression>
                    e.level.toInt() == INFO.toInt()
                expression>
            evaluator>
            <OnMismatch>DENYOnMismatch>
            <OnMatch>NEUTRALOnMatch>
        filter>
        
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.home}/logback-info.log.%d{yyyy-MM-dd}fileNamePattern>
            <maxHistory>2maxHistory>
        rollingPolicy>
        <encoder charset="utf-8">
            
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%npattern>
        encoder>
    appender>

    
    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARNlevel>
        filter>
        
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.home}/logback-error.log.%d{yyyy-MM-dd}fileNamePattern>
            <maxHistory>2maxHistory>
        rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%npattern>
            <charset>UTF-8charset>
        encoder>
    appender>

    
    <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>

你可能感兴趣的:(logback.xml 基本配置)