Home  >  Article  >  Java  >  How to implement Spring Boot Actuator management log

How to implement Spring Boot Actuator management log

王林
王林forward
2023-05-12 18:01:12955browse

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:

  
            org.springframework.boot
            spring-boot-starter-actuator
            ${spring-boot.version}
 

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:

 
                级别:
                
                  
                  
                  
                 

文件: 查看
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:

How to implement Spring Boot Actuator management log

How to implement Spring Boot Actuator management log

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete