SpringBoot日志使用记录

知识点1,默认开启日志系统,info级别

springboot starter中默认支持log4j2,logback

这里引入slf4j相关的logger包

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class StudyRestApplicationTests {
	
	private Logger logger = LoggerFactory.getLogger(StudyRestApplicationTests5.class);

	@Test
	public void testLog() {
		logger.trace("trace***");
		logger.debug("debug***");
		logger.info("info***");
		logger.warn("warn***");
		logger.error("error***");
	}
}

打印结果

2021-01-13 23:11:15.130  INFO 19536 --- [           main] c.e.s.StudyRestApplicationTests5         : info***
2021-01-13 23:11:15.131  WARN 19536 --- [           main] c.e.s.StudyRestApplicationTests5         : warn***
2021-01-13 23:11:15.131 ERROR 19536 --- [           main] c.e.s.StudyRestApplicationTests5         : error***

知识点2,日志级别设置

logging.level.项目包名=日志级别,举例

logging.level.com.example.studyRest=warn

打印结果

2021-01-13 23:14:55.478  WARN 20836 --- [           main] c.e.s.StudyRestApplicationTests5         : warn***
2021-01-13 23:14:55.478 ERROR 20836 --- [           main] c.e.s.StudyRestApplicationTests5         : error***

知识点3,将日志写到文件夹下

logging.file.path=D:/log

默认生成文件:spring.log

知识点4,将日志写到指定文件中

ogging.file.name=D:/log/runtime.log

知识点5,日志格式

logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS};my-app;%msg%n
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS};my-app;%msg%n

详细pattern日志格式参考:https://blog.csdn.net/dengjili/article/details/98369441

springboot 官网Logging使用

https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-logging

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值