P60 Spring Boot添加日志

1.在项目部署到线上的时候,出错时,希望有机可寻,所以就可以打印日志,在配置文件中添加配置application.properties

logging.file.name=logs/community.log
logging.level.root=info
logging.file.max-history=15
logging.file.max-size=100MB

P60 Spring Boot添加日志

 

2.启动项目,就会生成相应的文件

P60 Spring Boot添加日志

项目运行的日志会自动追加到文件里

P60 Spring Boot添加日志

2.git设置不想提交的文件

2.1 在项目下找到(.gitignore)

P60 Spring Boot添加日志

2.2 忽略logs/下的文件

P60 Spring Boot添加日志

3.给自己的项目打日志

1.添加来自lombok的日志文件

1.1 添加 @Slf4j 注解 自动的将log注入

P60 Spring Boot添加日志

2.在需要的地方打日志

log.error("callback get error,{}",githubUser);

P60 Spring Boot添加日志