springboot中抽离日志

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <contextName>myProject</contextName>
    <property name="log.path" value="log"/>
    <property name="log.maxHistory" value="15"/>
    <property name="log.colorPattern"
              value="%d{yyyy-MM-dd HH:mm:ss} | %highlight(%-5level) | %boldYellow(%thread) | %boldGreen(%logger) | %msg%n"/>
    <property name="log.pattern"
              value="%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n"/>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${log.colorPattern}</pattern>
        </encoder>
    </appender>

    <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/info/info.%d{yyyy-MM-dd}.log</fileNamePattern>
            <MaxHistory>${log.maxHistory}</MaxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>NEUTRAL</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
            <evaluator>
                <!-- 默认为 ch.qos.logback.classic.boolex.JaninoEventEvaluator -->
                <!--过滤掉所有日志消息中不包含"IniCronRunner"字符串的日志。-->
                <expression>return message.contains(" CONFIG CRON JOB");</expression>
            </evaluator>
            <!--用于配置符合过滤条件的操作。-->
            <OnMatch>DENY</OnMatch>
            <!--用于配置不符合过滤条件的操作-->
            <OnMismatch>ACCEPT</OnMismatch>
        </filter>

    </appender>

    <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/error/error.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <appender name="azure_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名-->
            <FileNamePattern>
                ${log.path}/other/azure/azure_log.%d{yyyy-MM-dd}.%i.log
            </FileNamePattern>
            <cleanHistoryOnStart>false</cleanHistoryOnStart>
            <!-- 最多保存30天日志-->
            <MaxHistory>30</MaxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!--日志文件最大的大小-->
                <maxFileSize>30MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %logger - %msg%n
            </Pattern>
        </encoder>
    </appender>


    <appender name="cron_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名-->
            <FileNamePattern>
                ${log.path}/other/cron/cron_log.%d{yyyy-MM-dd}.%i.log
            </FileNamePattern>
            <cleanHistoryOnStart>false</cleanHistoryOnStart>
            <!-- 最多保存30天日志-->
            <MaxHistory>30</MaxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!--日志文件最大的大小-->
                <maxFileSize>30MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %logger - %msg%n
            </Pattern>
        </encoder>
    </appender>
    <appender name="api_log" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--日志文件输出的文件名-->
            <FileNamePattern>
                ${log.path}/other/api/api_log.%d{yyyy-MM-dd}.%i.log
            </FileNamePattern>
            <cleanHistoryOnStart>false</cleanHistoryOnStart>
            <!-- 最多保存30天日志-->
            <MaxHistory>30</MaxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!--日志文件最大的大小-->
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %logger - %msg%n
            </Pattern>
        </encoder>
    </appender>
    <root level="debug">
        <appender-ref ref="console"/>
    </root>

    <root level="info">
        <appender-ref ref="file_info"/>
        <appender-ref ref="file_error"/>
    </root>
    <logger name="com.test.system.service.trigger.AzureTrigger" level="info" additivity="true">
        <appender-ref ref="azure_log"/>
    </logger>
    <logger name="com.test.system.schedule">
        <appender-ref ref="cron_log"/>
    </logger>
    <logger name="com.test.system.api">
        <appender-ref ref="api_log"/>
    </logger>
 
</configuration>
相关推荐
TangKenny8 分钟前
计算网络信号
java·算法·华为
肘击鸣的百k路9 分钟前
Java 代理模式详解
java·开发语言·代理模式
城南vision16 分钟前
Docker学习—Docker核心概念总结
java·学习·docker
wyh要好好学习23 分钟前
SpringMVC快速上手
java·spring
尢词25 分钟前
SpringMVC
java·spring·java-ee·tomcat·maven
Mr. zhihao32 分钟前
享元模式在 JDK 中的应用解析
java·享元模式
茶馆大橘35 分钟前
微服务系列五:避免雪崩问题的限流、隔离、熔断措施
java·jmeter·spring cloud·微服务·云原生·架构·sentinel
wrx繁星点点35 分钟前
享元模式:高效管理共享对象的设计模式
java·开发语言·spring·设计模式·maven·intellij-idea·享元模式
真的想不出名儿39 分钟前
Java基础——反射
java·开发语言
鱼跃鹰飞40 分钟前
大厂面试真题-简单说说线程池接到新任务之后的操作流程
java·jvm·面试