logback配置

<?xml versoin="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <!-- 上下文属性 -->
    <property name="LOG_BASE" value="/home/log"></property>

    <!-- 系统日志按时间段输出到文件 -->
    <appender name="infoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logbak.classic.filter.ThresholdFilter"> <!-- 过滤低于设置级别的日志 -->
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_BASE}/info.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- 错误日志按时间段输出到文件 -->
    <appender name="errorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logbak.classic.filter.ThresholdFilter"> <!-- 过滤低于设置级别的日志 -->
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_BASE}/error.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- 控制第三方包的日志 -->
    <logger name="org.springframework" level="WARN" />

    <root level="INFO">
        <appender-ref ref="infoLog" />
        <appender-ref ref="errorLog" />
    </root>
</configuration>


你可能感兴趣的:(logback配置)