日志配置文件

不羁的心 提交于 2019-12-01 13:17:24
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="LOG_PATTERN" value="[ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n"/>

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

    <appender name="FILE-INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_PATH}/info.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>
                ${LOG_PATTERN}
            </pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_PATH}/error.log</File>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/error-%d{yyyyMMdd}.log.%i
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>2</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>
                ${LOG_PATTERN}
            </pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>


    <springProfile name="dev">
        <logger name="com.xxx.xx" level="INFO">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
        </logger>
    </springProfile>

    <springProfile name="local">
        <logger name="com.xxx.xx" level="debug">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
        </logger>
    </springProfile>

    <springProfile name="prod">
        <logger name="com.xxx.xx" level="INFO">
            <appender-ref ref="FILE-ERROR"/>
            <appender-ref ref="FILE-INFO"/>
        </logger>
    </springProfile>

    <root level="info">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE-ERROR"/>
        <appender-ref ref="FILE-INFO"/>
    </root>


    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <jmxConfigurator/>
</configuration>

按需求更改使用

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!