springboot 打印日志

在实际项目中,我们的程序都是运行在linux上,有错误时也不能在本地的控制台上直观看到,所有合理打印日志对于程序员迅速定位到错误;

我的项目是springboot,打印日志时的步骤:

1.application.yml配置文件中配置日志级别和日志文件的路径

logging:
  level:
    learning: debug
  file: log/app-user.log

2.在controller中定义log对象

private static final Logger log = LoggerFactory.getLogger(VehicelController.class);

3.打印日志

1.在关键的节点使用info打印

log.info("程序开始")
log.info("程序结束")

2.在处理异常处打印error

try{
    .....
    .....
}catch (Exception e) {
			e.printStackTrace();
			log.error("异常{}",e);;
		}

猜你喜欢

转载自blog.csdn.net/guangyingposuo/article/details/85234660
今日推荐