SpringBoot配置logback-spring.xml日志

在SpringBoot新建 logback-spring.xml 配置文件,因为SpringBoot官方是推荐这个方式

SpringBoot配置logback-spring.xml日志_第1张图片

内容,拷贝复制下来就可以了




    
    
    
    

    
    
        
        
            
            
                %d{yyyy-MM-dd HH:mm:ss.SSS} ----> [%thread] ---> %-5level %logger{50} - %msg%n
            
            
            
                %d{yyyy-MM-dd HH:mm:ss.SSS} ==== [%thread] ==== %-5level %logger{50} - %msg%n
            
        
    


    
    
        
        ${LOG_HOME}/${appName}.log
        
        
            
            ${LOG_HOME}/${appName}-%d{yyyy-MM-dd}-%i.log
            
            365
            
            
                100MB
            
        
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n
        
    


    
        ${LOG_HOME}/debug.log
        true
        
            ${LOG_HOME}/debug/%d{yyyy-MM-dd}/debug.%i.log.zip
            10MB
            7
            20GB
        
        
            [lf-1][${SERVER_NAME}][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%n
            
        
        
            DEBUG
            ACCEPT
            DENY
        
    

    
        ${LOG_HOME}/warn.log
        true
        
            ${LOG_HOME}/warn/%d{yyyy-MM-dd}/warn.%i.log.zip
            10MB
            7
            20GB
        
        
            [lf-1][${SERVER_NAME}][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%n
            
        
        
            WARN
            ACCEPT
            DENY
        
    

    
        ${LOG_HOME}/error.log
        true
        
            ${LOG_HOME}/error/%d{yyyy-MM-dd}/error.%i.log.zip
            10MB
            7
            20GB
        
        
            [lf-1][${SERVER_NAME}][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%n
            
        
        
            ERROR
            ACCEPT
            DENY
        
    

    
        ${LOG_HOME}/trace.log
        true
        
            ${LOG_HOME}/trace/%d{yyyy-MM-dd}/trace.%i.log.zip
            10MB
            7
            20GB
        
        
            [lf-1][${SERVER_NAME}][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%n
            
        
        
            TRACE
            ACCEPT
            DENY
        
    

    

    
    

    
    
        
        

        
        
    

    
    
        
    


 

测试代码:

package com.wjx;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {
    private Logger logger = LoggerFactory.getLogger(ApplicationTests.class);

    @Test
    public void contextLoads() {
    }


    @Test
    public void testLog() {
        logger.trace("这是 info 级别");
        logger.debug("这是 debug 级别");
        logger.info("这是 info 级别");
        logger.warn("这是 warn 级别");
        logger.error("这是 error 级别");
    }
}

测试日志截图

SpringBoot配置logback-spring.xml日志_第2张图片

你可能感兴趣的:(学习笔记)