欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

现有web系统替换成Spring Boot2框架 之4 日志框架 Spring Boot日志logback 

程序员文章站 2022-03-22 22:41:58
...

spring-boot-starter集成了日志组件,支持Java Util LoggingLog4J2Logback,使用哪个日志框架,在resources目录下添加响应的配置文件即可(logging.properties/log4j2-spring.xml/logback-spring.xml),这里以logback为例,增加logback-spring.xml文件,添加如下配置:

 

<?xml version="1.0" encoding="UTF-8" ?>

<configuration scan="true" scanPeriod="60 seconds">

  <appender name="smallbss" class="ch.qos.logback.core.rolling.RollingFileAppender">

    <file>logs/smallbss.log</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

      <fileNamePattern>logs/bat/boss.%d{yyyy-MM-dd}.log</fileNamePattern>

      <maxHistory>30</maxHistory>

      <totalSizeCap>3GB</totalSizeCap>

    </rollingPolicy>

    <encoder>

      <pattern>%d %-5level [%thread] %logger [line:%line]- %msg%n</pattern>

    </encoder>

  </appender>

  

  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">

     <encoder>

       <pattern>%d %-5level %logger [line:%line]- %msg%n</pattern>

     </encoder>

  </appender>

  <root level="INFO">

    <appender-ref ref="smallbss" /> 

    <appender-ref ref="console" /> 

  </root>

</configuration>