Springboot关闭默认的日志输出

本文环境

  1. springboot 2.2.6
  2. jdk 1.8.0_241

一、配置application.yml

resources目录下新建application.yml文件(或:application.properties),添加如下内容:

logging.level.[包名]: OFF

# 例如,OFF可改成某个日志级别
logging.level.org.apache.ignite: OFF

二、添加日志配置文件

  1. 添加log.xml文件,内容如下:

<configuration debug="false">
    
    <property name="LOG_HOME" value="/logs/log"/>
    
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%npattern>
        encoder>
    appender>

    
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/edusystem.log.%d{yyyy-MM-dd}.logFileNamePattern>
            
            <MaxHistory>30MaxHistory>
        rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%npattern>
        encoder>
        
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MBMaxFileSize>
        triggeringPolicy>
    appender>
    
    

    <logger name="com.edu.dao" level="DEBUG">logger>
    <logger name="org.apache.ignite" level="OFF">logger>
    
    <root level="INFO">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>
    root>
configuration>
  1. 在application.yml文件中引用该文件:
# 如果log.xml在resources目录下
logging.config: classpath:log.xml

# 如果log.xml在项目根目录或jar同级目录
logging.config: log.xml

你可能感兴趣的:(spring,Java与JVM,logback,java,spring,boot)