menu ChaYedan
logback配置
117 浏览 | 2022-07-10 | 阅读时间: 约 1 分钟 | 分类: | 标签:
请注意,本文编写于 139 天前,最后修改于 139 天前,其中某些信息可能已经过时。
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <property name="app.log.dir" value="./logs" />
    <property name="app.name" value="plutos" />

    <!-- 彩色日志 -->
    <!-- 彩色日志依赖的渲染类 -->
    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
        <!-- 例如:如果此处配置了INFO级别,则后面其他位置即使配置了DEBUG级别的日志,也不会被输出 -->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
        <encoder>
            <pattern>%level %d{yyyy-MM-dd HH:mm:ss.S}: ${app.name} [logid:%X{logid}] [KEY:%X{_TRACE_KEY}] * %thread [%logger{0}] [%msg]%n</pattern>
        </encoder>
    </appender>

    <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${app.log.dir}/${app.name}-info.log</File>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%level %d{yyyy-MM-dd HH:mm:ss.S}: ${app.name} [logid:%X{logid}] [KEY:%X{_TRACE_KEY}] * %thread [%logger{0}] [%msg]%n</pattern>
            <immediateFlush>false</immediateFlush>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${app.log.dir}/${app.name}-info-%d{yyyyMMdd}.log</FileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>

    </appender>

    <appender name="warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${app.log.dir}/${app.name}-warn.log</File>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%level %d{yyyy-MM-dd HH:mm:ss.S}: ${app.name} [logid:%X{logid}] * %thread [%logger{0}] [%msg]%n</pattern>
            <immediateFlush>false</immediateFlush>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${app.log.dir}/${app.name}-warn-%d{yyyyMMdd}.log</FileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${app.log.dir}/${app.name}-error.log</File>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%level %X{errorknown} %d{yyyy-MM-dd HH:mm:ss.S}:${app.name} [logid:%X{logid}] * %thread [%logger{0}] [%msg]%n</pattern>
            <immediateFlush>true</immediateFlush>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${app.log.dir}/${app.name}-error-%d{yyyyMMdd}.log</FileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="console" />
        <appender-ref ref="info" />
        <appender-ref ref="warn" />
        <appender-ref ref="error" />
    </root>

</configuration>
知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

发表评论

email
web

全部评论 (暂无评论)

info 还没有任何评论,快来留言吧!