ホームページ  >  記事  >  Java  >  Spring Boot Actuator管理ログの実装方法

Spring Boot Actuator管理ログの実装方法

王林
王林転載
2023-05-12 18:01:121018ブラウズ

次の 2 つの問題を解決するには:

1. 単一の JAR パッケージ アプリケーションがログを参照する必要がある場合、ログを参照するためにサーバーにリモート アクセスしてログインするのは比較的面倒です。

2. 本番環境 BUGを解決するには一時的にログレベルを変更する必要があり、サービスの再起動では解決できません。

そこでアクチュエーターの一部を利用して解決しました。 2つの問題。

最初にアクチュエータの依存関係を POM ファイルに導入します:

  <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 },
"ログファイル: "{"href":"http://localhost:8085/actuator/logfile","templated":false},"loggers":{"href":"http ://localhost: 8085/actuator/loggers","template":false},"loggers-name":{"href":"http://localhost:8085/actuator/loggers/{name}","template ":true}} }

    logfile は表示ログ ファイルです。
  • loggers は表示ログです。 level
  • 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: {&#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
          });
        }
      });
 }

最終的な効果は次のとおりです:

Spring Boot Actuator管理ログの実装方法

以上がSpring Boot Actuator管理ログの実装方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はyisu.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。