Springboot日志配置

  1. 1:项目搭建图:
  2. 2.application.yml配置
  3. 3.logback-spring.xml内容:
  4. 理解参考

1:项目搭建图:

2.application.yml配置

logging.path: log
logging.config: src/main/resources/config/logback-spring.xml

3.logback-spring.xml内容:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
<configuration scan="true" scanPeriod="10 seconds">
   <!--  <include resource="org/springframework/boot/logging/logback/base.xml" /> -->

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">  
        <encoder>  
          <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>  
        </encoder>  
      </appender> 

    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_PATH}/LottSellManageCW.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 每天压缩前天的日志,压缩为gz格式 -->
            <fileNamePattern>${LOG_PATH}/surrogateService-%d{yyyyMMdd}.%i.gz</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- 多大空间分割日志 -->
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- 最大保存文件数 -->
            <maxHistory>400</maxHistory> 

        </rollingPolicy>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
            </Pattern>
        </layout>
    </appender>

    <logger name="org.springframework" additivity="false">  
        <level value="INFO" />  
        <appender-ref ref="STDOUT"/>  
        <appender-ref ref="INFO_FILE"/>  
    </logger> 

    <logger name="org.rythmengine" additivity="false">  
        <level value="INFO" />  
        <appender-ref ref="STDOUT"/>  
        <appender-ref ref="INFO_FILE"/>  
    </logger>

    <root level="DEBUG">
        <appender-ref ref="INFO_FILE" />
        <appender-ref ref="STDOUT" />  
    </root>

</configuration>

理解参考

日志解析详情

文章标题:Springboot日志配置

发布时间:2019-11-14, 15:19:38

最后更新:2019-11-14, 15:19:39