日誌器 (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" ]
}
}
}
檢索單個日誌記錄器
要檢索單個日誌記錄器,請向 /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"
}
檢索單個組
要檢索單個組,請向 /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" ]
}
設定日誌級別
要設定日誌記錄器的級別,請向 /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。