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

logback配置

程序员文章站 2022-07-03 17:27:07
...
<?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>


转载于:https://my.oschina.net/u/145060/blog/338154

上一篇: 常用命令

下一篇: logback配置