Spring Boot Actuator管理日志如何实现
为了解决以下两个问题:1、单JAR包应用查看日志需要的时候如果需要远程访问服务器登录查看日志,那样相对比较麻烦2、生产环境为了解决BUG需要临时更换日志级别,总不能重启服务来解决吧所以使用了actuator其中的部分来解决这两个问题。首先在POM文件中引入actuator依赖:org.springframework.bootspring-boot-starter-actuator${spring-boot.version}配置文件中配置:management.endpoints.web.base-path
为了解决以下两个问题:
1、单JAR包应用查看日志需要的时候如果需要远程访问服务器登录查看日志,那样相对比较麻烦
2、生产环境为了解决BUG需要临时更换日志级别,总不能重启服务来解决吧
所以使用了actuator 其中的部分来解决这两个问题。
首先在POM文件中引入actuator依赖:
org.springframework.boot spring-boot-starter-actuator ${spring-boot.version}
配置文件中配置:
management.endpoints.web.base-path=/actuator management.endpoints.web.exposure.include=logfile,loggers management.endpoint.health.show-details=always logging.file.name=logs/EL-3KJ/EL-3KJ.log
然后直接可以访问 http://localhost:8085/actuator
得到下列结果:
{"_links":{
"self"{"href":"http://localhost:8085/actuator","templated":false},
"logfile: {"href":"http://localhost:8085/actuator/logfile","templated":false},"loggers":{"href":"http://localhost:8085/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:8085/actuator/loggers/{name}","templated":true}}}
其中
logfile 是查看日志文件
loggers是查看日志级别
loggers/{name}是更改日志级别
前端参考代码:
级别: this.logfileurl = res.dataApi+"actuator/logfile"; this.loglevelurl = res.dataApi+"actuator/loggers/root"; getLogLevel(){ this.ajax_get({ url: this.loglevelurl, params: {}, }).then((res) => { this.loglevel=res.configuredLevel }); }, lvChange(){ this.changeLogLevel(this.loglevel) }, changeLogLevel(level){ this.ajax_post({ url: this.tenant.dataApi + "actuator/loggers/root", params: {'configuredLevel':level}, }).then((res) => { this.spinShow = false; if (!res.code) { this.$Notice.success({ title:'更改日志级别为'+level, desc:res.msg }); } else { this.$Notice.error({ title:'更改日志级别失败', desc:res.msg }); } }); }
文件: 查看
最终效果如下:


Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。
极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。
















