Spring Boot Actuator管理日志的实现
作者:墨着染霜华 时间:2023-02-12 10:45:40
为了解决以下两个问题:
1、单JAR包应用查看日志需要的时候如果需要远程访问服务器登录查看日志,那样相对比较麻烦
2、生产环境为了解决BUG需要临时更换日志级别,总不能重启服务来解决吧
所以使用了actuator 其中的部分来解决这两个问题。
首先在POM文件中引入actuator依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring-boot.version}</version>
</dependency>
配置文件中配置:
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}是更改日志级别
前端参考代码:
<TabPane label="接口日志" name="name3">
级别:
<RadioGroup v-model="loglevel" type="button" size="small" @on-
change="lvChange()">
<Radio label="ERROR"></Radio>
<Radio label="INFO"></Radio>
<Radio label="DEBUG"></Radio>
</RadioGroup> <br/><br/>
文件:<a :href="logfileurl" rel="external nofollow" target="_blank" > 查看</a>
</TabPane>
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
});
}
});
}
最终效果如下:
来源:https://blog.csdn.net/chengmin123456789/article/details/125597951
标签:Spring,Boot,Actuator,日志
0
投稿
猜你喜欢
总结Java集合类操作优化经验
2023-01-27 10:29:37
java基于AES对称加密算法实现的加密与解密功能示例
2023-02-07 13:34:47
C语言实现哈夫曼编码
2022-07-25 07:35:04
C#实现在启动目录创建快捷方式的方法
2021-05-29 13:54:21
Unity3D实现物体旋转缩放移动效果
2023-07-17 22:11:58
Java泛型机制与反射原理相关知识总结
2023-11-11 06:02:15
springboot 定时任务@Scheduled实现解析
2023-11-10 16:18:24
AndroidStudio接入Unity工程并实现相互跳转的示例代码
2023-08-06 23:34:51
C#中值类型和引用类型解析
2023-02-10 22:41:33
Java Collection集合iterator方法解析
2022-11-17 06:43:29
Logback动态修改日志级别的方法
2023-05-30 21:47:01
Android自定义控件ListView下拉刷新的代码
2023-04-07 23:51:06
Java设计模式之桥接模式的实现
2021-10-18 20:29:04
C#操作windows系统进程的方法
2023-09-01 03:13:26
Java 编程中十个处理异常的建议
2022-10-27 11:34:41
Android开发中匿名设备标识符OAID使用及初始化
2023-12-23 04:33:54
Android View的事件分发机制深入分析讲解
2023-06-18 21:28:49
c#实现数据同步的方法(使用文件监控对象filesystemwatcher)
2021-11-27 03:03:46
java 自动生成略缩图示例代码
2021-11-11 01:27:37
解决springboot启动失败的问题('hibernate.dialect' not set)
2023-11-09 03:21:21