欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring?Boot?Actuator管理日志的實現(xiàn)

 更新時間:2022年07月04日 16:35:56   作者:墨著染霜華  
本文主要介紹了Spring?Boot?Actuator管理日志的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

為了解決以下兩個問題:

1、單JAR包應用查看日志需要的時候如果需要遠程訪問服務器登錄查看日志,那樣相對比較麻煩

2、生產(chǎn)環(huán)境為了解決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
          });
        }
      });
 }

最終效果如下:

 到此這篇關于Spring Boot Actuator管理日志的實現(xiàn)的文章就介紹到這了,更多相關Spring Boot Actuator管理日志內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論