Spring Boot利用lombok插件注解SLF4J2日志打印配置文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <contextName>logback</contextName>
    <!-- logger标签定义包下日志级别 -->
    <logger name="org.springframework" level="error"/>
    <logger name="org.springboot.sample" level="error"/>
    <logger name="com.lei.tang" level="debug"/>
    <property name="log.path" value="日志存储路径"/>
    <property name="log.name" value="日志名称"/>

    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/${log.name}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 每天一归档 -->
            <fileNamePattern>${log.path}/${log.name}.%d{yyyy-MM-dd}.log.zip</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %level [%thread] %logger{36} [%file : %line] %msg%n</pattern>
            <charset class="java.nio.charset.Charset">UTF-8</charset>
        </encoder>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>100MB</maxFileSize>
        </triggeringPolicy>
    </appender>

    <root level="warn">
        <appender-ref ref="file"/>
    </root>
</configuration>

按照从低到高为:All < Trace < Debug < Info < Warn < Error < Fatal < OFF
可能因环境不同,日志级别不同,我们可以在项目的主配置文件中通过logging:config: classpath:日志xml文件路径(classpath:log4j2.xml)

猜你喜欢

转载自blog.csdn.net/weixin_41131531/article/details/89922240