外采平台slf4j日志配置详解

/ 技术 / 无站内评论 / 298浏览
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
    <!-- 设置日志输出根目录 -->
    <property name="log.dir" value="${catalina.base}/logs"/>
    <!-- 设置编码 -->
    <property name="encoding" value="UTF-8"/>
    <!-- 格式化输出时间 级别 类全名 发送的绝对路径 等信息 -->
    <property name="normal-pattern" value="[%d{yyyy-MM-dd HH🇲🇲ss} %5p %c:%L] %X{QTRACER} %X{USER} %X{COMPANY} %m%n"/>

    <appender name="consoleApender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder charset="UTF-8">
            <pattern>${normal-pattern}</pattern>
        </encoder>
    </appender>


    <appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- 过滤掉所有低于ERROR级别的日志。 ThresholdFilter 过滤器-->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <file>${log.dir}/errors.log</file>
        <encoder charset="UTF-8">
            <pattern>${normal-pattern}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.dir}/errors.%d{yyyy-MM-dd-HH}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="mainAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.dir}/main.log</file>
        <encoder charset="UTF-8">
            <pattern>${normal-pattern}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.dir}/main.%d{yyyy-MM-dd-HH}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="databaseAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.dir}/database.log</file>
        <encoder charset="UTF-8">
            <pattern>${normal-pattern}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.dir}/database.%d{yyyy-MM-dd-HH}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <appender name="dbAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.dir}/db.log</file>
        <encoder charset="UTF-8">
            <pattern>[%d{yyyy-mm-dd HH🇲🇲ss.SSS} %t %-5p %L] %m%n</pattern>
        </encoder>
        <param name="append" value="true" />
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.dir}/db.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
    </appender>

    <!-- info日志 appender  -->
    <appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 按天回滚 daily -->
            <fileNamePattern>${log.dir}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!-- 日志最大的历史 60天 -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder charset="UTF-8">
            <pattern>${normal-pattern}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <!-- <level>:设置过滤级别  -->
            <level>INFO</level>
            <!-- <onMatch>:用于配置符合过滤条件的操作  -->
            <onMatch>ACCEPT</onMatch>
            <!-- <onMismatch>:用于配置不符合过滤条件的操作 -->
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <logger name="com.qunar.flight.snail.dao" additivity="false" level="debug">
        <appender-ref ref="databaseAppender"/>
    </logger>

    <logger name="com.qunar.redis.storage" additivity="false" level="info">
        <appender-ref ref="dbAppender"/>
    </logger>

    <logger name="com.qunar.flight.snail" level="debug"/>

    <logger name="com.qunar.db.util.DbLogger" level="warn"/>

    <logger name="com.qunar.flight.outsourcing" level="info">
        <appender-ref ref="infoAppender"></appender-ref>
    </logger>

    <root level="info">
        <appender-ref ref="errorAppender"/>
        <appender-ref ref="mainAppender"/>
        <appender-ref ref="consoleApender"/>
    </root>
</configuration>
召唤蕾姆
琼ICP备18000156号

鄂公网安备 42011502000211号