Home > Java > javaTutorial > body text

How to implement Spring Boot Actuator management log

王林
Release: 2023-05-12 18:01:12
forward
1062 people have browsed it

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>
Copy after login

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
Copy after login

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: {&#39;configuredLevel&#39;:level},
      }).then((res) => {
        this.spinShow = false;
        if (!res.code) {
          this.$Notice.success({
            title:&#39;更改日志级别为&#39;+level,
            desc:res.msg
          });
        } else {
          this.$Notice.error({
            title:&#39;更改日志级别失败&#39;,
            desc:res.msg
          });
        }
      });
 }
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template