Spring Boot Actuator管理日志的实现
作者:墨着染霜华 发布时间:2023-02-12 10:45:40
标签:Spring,Boot,Actuator,日志
为了解决以下两个问题:
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
0
投稿
猜你喜欢
- XSS ,全名:cross-site scripting(跨站点脚本),是当前 web 应用中最危险和最普遍的漏洞之一。攻击者尝试注入恶意脚
- 承接上文 传送门一.完善登录功能按照常理,只有登陆过后才能进入首页,若没有登陆则应当直接跳转到登陆页面,这样的场景不就完美契合过滤器的功效吗
- SpringMVC一般使用MultipartFile来做文件的上传,通过MultipartFile的getContentType()方法判定
- 这篇文章主要介绍了Java String的intern用法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
- Allatori混淆技术介绍Allatori是一个Java 混淆器,它属于第二代混淆器,因此它能够全方位地保护你的知识产权。 Allator
- 在使用多线程过程中,可能会遇到在一些情况下必须等待子线程全部执行结束后主线程才进行下一步,做法如下: //在使用多线程过程中,可能会遇到在一
- 一、进程内部的线程同步1、使用lock,用法如下:private static readonly object SeqLock = new
- 具体解释请仔细看注释里已经讲解的很细致了,这里就不多废话了using UnityEngine;using System.Collection
- GridView是类似于ListView的控件,只是GridView可以使用多个列来呈现内容,而ListView是以行为单位,所以用法上是差
- 模式介绍命令模式(Command Pattern) :在软件设计中,我们经常需要向某些对象发送请求,但是并不知道请求的接收者是谁,也不知道被
- 本文实例讲述了C#中累加器函数Aggregate用法。分享给大家供大家参考。具体如下:var shouldExclude = false;v
- 1. 前言Spring提供了xml、注解、JavaConfig多种方式来配置bean,不论何种方式,Spring最终都会将bean封装成Be
- java 中ArrayList与LinkedList性能比较今天看一框架的代码,看到有些 可以使用ArrayList的地方 使用的是 Lin
- 一、首先在主布局中,用帧布局来填充 RecycleView 和 两个模拟发送消息的Button<?xml version="
- 在上周发布的 TienChin 项目视频中,我和大家一共梳理了六种幂等性解决方案,接口幂等性处理算是一个非常常见的需求了,我们在很多项目中其
- 需求使用 spring-boot 项目开发中,项目启动时“非常”慢的。如果每次修改代码或静态资源文件后都需要重新启动项目,这是多么痛苦的事。
- 一、 看效果二、上代码package com.framework.widget;import android.app.Activity;im
- 经常遇到的问题在实际得开发过程中,我们经常会遇到以下场景,我们后端请求某个接口后获取到得数据,不希望将所有字段都返回给前端,那么我们需要封装
- Mybatis配置返回为修改影响条数mybatis执行update()方法默认返回为匹配的更新记录条数,现在需要将update()方法修改为
- 实践过程效果代码public partial class Form1 : Form{ public Form1()