日誌器 (loggers)

loggers 端點提供對應用程式日誌記錄器及其級別配置的訪問。

檢索所有日誌記錄器

要檢索應用程式的日誌記錄器,請向 /actuator/loggers 發出 GET 請求,如以下基於 curl 的示例所示

$ curl 'https://:8080/actuator/loggers' -i -X GET

結果響應類似於以下內容

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 791

{
  "levels" : [ "OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" ],
  "loggers" : {
    "ROOT" : {
      "configuredLevel" : "INFO",
      "effectiveLevel" : "INFO"
    },
    "com.example" : {
      "configuredLevel" : "DEBUG",
      "effectiveLevel" : "DEBUG"
    }
  },
  "groups" : {
    "test" : {
      "configuredLevel" : "INFO",
      "members" : [ "test.member1", "test.member2" ]
    },
    "web" : {
      "members" : [ "org.springframework.core.codec", "org.springframework.http", "org.springframework.web", "org.springframework.boot.actuate.endpoint.web", "org.springframework.boot.web.servlet.ServletContextInitializerBeans" ]
    },
    "sql" : {
      "members" : [ "org.springframework.jdbc.core", "org.hibernate.SQL", "org.jooq.tools.LoggerListener" ]
    }
  }
}

響應結構

響應包含應用程式日誌記錄器的詳細資訊。下表描述了響應的結構

路徑 型別 描述

級別

陣列

日誌系統支援的級別。

日誌記錄器

物件

按名稱鍵入的日誌記錄器。

groups

物件

按名稱鍵入的日誌記錄器組

loggers.*.configuredLevel

字串

日誌記錄器的配置級別(如果有)。

loggers.*.effectiveLevel

字串

日誌記錄器的有效級別。

groups.*.configuredLevel

字串

日誌記錄器組的配置級別(如果有)。

groups.*.members

陣列

屬於此組的日誌記錄器

檢索單個日誌記錄器

要檢索單個日誌記錄器,請向 /actuator/loggers/{logger.name} 發出 GET 請求,如以下基於 curl 的示例所示

$ curl 'https://:8080/actuator/loggers/com.example' -i -X GET

上述示例檢索有關名為 com.example 的日誌記錄器的資訊。生成的響應與以下內容類似

HTTP/1.1 200 OK
Content-Disposition: inline;filename=f.txt
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 61

{
  "configuredLevel" : "INFO",
  "effectiveLevel" : "INFO"
}

響應結構

響應包含請求日誌記錄器的詳細資訊。下表描述了響應的結構

路徑 型別 描述

configuredLevel

字串

日誌記錄器的配置級別(如果有)。

effectiveLevel

字串

日誌記錄器的有效級別。

檢索單個組

要檢索單個組,請向 /actuator/loggers/{group.name} 發出 GET 請求,如以下基於 curl 的示例所示

$ curl 'https://:8080/actuator/loggers/test' -i -X GET

上述示例檢索有關名為 test 的日誌記錄器組的資訊。生成的響應與以下內容類似

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 82

{
  "configuredLevel" : "INFO",
  "members" : [ "test.member1", "test.member2" ]
}

響應結構

響應包含請求組的詳細資訊。下表描述了響應的結構

路徑 型別 描述

configuredLevel

字串

日誌記錄器組的配置級別(如果有)。

成員

陣列

屬於此組的日誌記錄器

設定日誌級別

要設定日誌記錄器的級別,請向 /actuator/loggers/{logger.name} 發出 POST 請求,並在 JSON 正文中指定日誌記錄器的配置級別,如以下基於 curl 的示例所示

$ curl 'https://:8080/actuator/loggers/com.example' -i -X POST \
    -H 'Content-Type: application/json' \
    -d '{"configuredLevel":"debug"}'

上述示例將 com.example 日誌記錄器的 configuredLevel 設定為 DEBUG

請求結構

請求指定日誌記錄器的所需級別。下表描述了請求的結構

路徑 型別 描述

configuredLevel

字串

日誌記錄器的級別。可以省略以清除級別。

設定組的日誌級別

要設定日誌記錄器的級別,請向 /actuator/loggers/{group.name} 發出 POST 請求,並在 JSON 正文中指定日誌記錄器組的配置級別,如以下基於 curl 的示例所示

$ curl 'https://:8080/actuator/loggers/test' -i -X POST \
    -H 'Content-Type: application/json' \
    -d '{"configuredLevel":"debug"}'

上述示例將 test 日誌記錄器組的 configuredLevel 設定為 DEBUG

請求結構

請求指定日誌記錄器組的所需級別。下表描述了請求的結構

路徑 型別 描述

configuredLevel

字串

日誌記錄器的級別。可以省略以清除級別。

清除日誌級別

要清除日誌記錄器的級別,請向 /actuator/loggers/{logger.name} 發出 POST 請求,並在 JSON 正文中包含一個空物件,如以下基於 curl 的示例所示

$ curl 'https://:8080/actuator/loggers/com.example' -i -X POST \
    -H 'Content-Type: application/json' \
    -d '{}'

上述示例清除了 com.example 日誌記錄器的配置級別。

© . This site is unofficial and not affiliated with VMware.