【SpringBoot】SpringBoot配置logging日志及输出日志:


一、application.properties/application.yml

在这里插入图片描述

#不同目录下的日志可配置不同级别
#logging.level.root= warn
#logging.level.org-springframework-web=debug
#logging.level.org-hibernate= error

#采用相对路径方式将日志文件输出到【projectlog/project.log】
logging.file.name= projectlog/project.log
logging.file.max-history=100

#自定义日志输出格式
logging.pattern.console= %d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n
logging.pattern.file=%d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n

或者

logging:
   #level:
   #   root: "warn"
   #   org.springframework.web: "debug"
   #   org.hibernate: "error"
   file: 
      name: projectlog/project.log
   max-history: 100
   pattern:
      console: "%d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n"
      file: "%d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n"

二、测试并输出日志:

在这里插入图片描述

package com.kd.demo.mapper;

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;


@SpringBootTest
@RunWith(SpringRunner.class)
public class LogMapperTest {
    
    

    protected static final Logger logger = LoggerFactory.getLogger(LogMapperTest.class);

    @Test
    public void LogTest() {
    
    
        logger.error("===系统调用了LogMapperTest===");
    }
}

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_53791978/article/details/130470146