In order to solve the following two problems:
1. When a single JAR package application needs to view logs, it is relatively troublesome to remotely access the server to log in to view logs.
2. Production environment In order to solve the BUG, the log level needs to be temporarily changed. It cannot be solved by restarting the service.
So I used part of the actuator to solve these two problems.
First introduce the actuator dependency in the POM file:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>${spring-boot.version}</version> </dependency>
Configure in the configuration file:
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
Then you can directly access http://localhost:8085/actuator
Get the following results:
{"_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 is the view log file
loggers is the view log level
loggers/{name} is to change the log level
Front-end reference code:
<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 }); } }); }
The final effect is as follows:
The above is the detailed content of How to implement Spring Boot Actuator management log. For more information, please follow other related articles on the PHP Chinese website!