跳到主要内容

日志记录器 (loggers)

DeepSeek V3 中英对照 Loggers (loggers) Loggers (loggers)

loggers 端点提供了对应用程序日志记录器及其级别配置的访问。

获取所有日志记录器

要获取应用程序的日志记录器,请向 /actuator/loggers 发起一个 GET 请求,如下面的基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/loggers' -i -X GET
bash

生成的响应类似于以下内容:

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" ]
}
}
}
http

响应结构

响应包含了应用程序日志记录器的详细信息。下表描述了响应的结构:

路径类型描述
levelsArray日志系统支持的级别。
loggersObject按名称键控的记录器。
groupsObject按名称键控的记录器组
loggers.*.configuredLevelString记录器的配置级别,如果有的话。
loggers.*.effectiveLevelString记录器的有效级别。
groups.*.configuredLevelString记录器组的配置级别,如果有的话。
groups.*.membersArray属于该组的记录器

获取单个 Logger

要检索单个日志记录器,请向 /actuator/loggers/{logger.name} 发送 GET 请求,如下面的基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/loggers/com.example' -i -X GET
bash

前面的示例检索了名为 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"
}
http

响应结构

响应包含了所请求记录器的详细信息。下表描述了响应的结构:

路径类型描述
configuredLevelString日志记录器的配置级别(如果有)。
effectiveLevelString日志记录器的有效级别。

获取单个分组

要检索单个组,请向 /actuator/loggers/{group.name} 发起 GET 请求,如下面的基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/loggers/test' -i -X GET
bash

前面的示例检索了名为 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" ]
}
http

响应结构

响应中包含了所请求群组的详细信息。下表描述了响应的结构:

路径类型描述
configuredLevelString日志记录器组配置的日志级别(如果存在)。
membersArray属于该组的日志记录器

设置日志级别

要设置日志记录器的级别,请向 /actuator/loggers/{logger.name} 发起一个 POST 请求,并在 JSON 请求体中指定日志记录器的配置级别,如下面基于 curl 的示例所示:

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

前面的示例将 com.example 日志记录器的 configuredLevel 设置为 DEBUG

请求结构

该请求指定了日志记录器的期望级别。下表描述了该请求的结构:

路径类型描述
configuredLevelString日志记录器的级别。可以省略以清除级别。

为组设置日志级别

要设置日志记录器的级别,请向 /actuator/loggers/{group.name} 发起一个 POST 请求,并在 JSON 请求体中指定日志记录器组的配置级别,如下面基于 curl 的示例所示:

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

前面的示例将 test 日志记录器组的 configuredLevel 设置为 DEBUG

请求结构

请求指定了日志记录器组的期望级别。下表描述了请求的结构:

路径类型描述
configuredLevelString日志记录器的级别。可以省略以清除级别。

清除日志级别

要清除日志记录器的级别,可以向 /actuator/loggers/{logger.name} 发送一个 POST 请求,并在请求体中包含一个空对象的 JSON,如下面这个基于 curl 的示例所示:

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

前面的示例清除了 com.example 日志记录器的配置级别。