使用 spring-boot-starter-actuator 动态修改项目日志级别,这也是今天在网上查日志相关的问题发现的骚操作,所以自己试了一下,感觉这个太牛批了,操作也很简单
- 我目前用的是最新的 springboot 版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
- 在项目中增加 maven 依赖
<!-- 健康检查和一些监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- 配置文件 application.yml 增加配置,开放端口访问权限,不然访问不了
# 健康检查相关配置
management:
endpoints:
web:
exposure:
include: '*'
然后现在就可以开始访问接口了
- 查看日志级别:不传包名默认是所有包的日志级别信息,传包名就是指定包的日志级别了
请求格式:GET http://[ip]:[port]/actuator/loggers/[package]
修改前
- 查看日志级别:不传包名默认是所有包的日志级别信息,传包名就是指定包的日志级别了
- 2.修改日志级别:包名root表示修改全部,传入则修改指定包日志级别
请求格式:GET http://[ip]:[port]/actuator/loggers/[package]
修改后
网友评论