对于最新的稳定版本,请使用 Spring Boot 3.4.0! |
记录器 (loggers
)
这loggers
endpoint 提供对应用程序的 Logger 及其级别的配置的访问权限。
检索所有记录器
要检索应用程序的记录器,请创建一个GET
request 添加到/actuator/loggers
,如以下基于 curl 的示例所示:
$ curl 'http://localhost: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" ]
}
}
}
响应结构
响应包含应用程序的记录器的详细信息。 下表描述了响应的结构:
路径 | 类型 | 描述 |
---|---|---|
|
|
日志记录系统支持的级别。 |
|
|
按 name 键控的 Logger。 |
|
|
按名称键控的记录器组 |
|
|
记录器的配置级别(如果有)。 |
|
|
记录器的有效水平。 |
|
|
记录器组的配置级别(如果有)。 |
|
|
属于此组的 Logger |
检索单个 Logger
要检索单个 Logger,请创建一个GET
request 添加到/actuator/loggers/{logger.name}
,如以下基于 curl 的示例所示:
$ curl 'http://localhost: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"
}
检索单个组
要检索单个组,请创建一个GET
request 添加到/actuator/loggers/{group.name}
,
如以下基于 curl 的示例所示:
$ curl 'http://localhost: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" ]
}
设置日志级别
要设置 Logger 的级别,请创建一个POST
request 添加到/actuator/loggers/{logger.name}
替换为 JSON 正文,该正文指定 Logger 的配置级别,如以下基于 curl 的示例所示:
$ curl 'http://localhost:8080/actuator/loggers/com.example' -i -X POST \
-H 'Content-Type: application/json' \
-d '{"configuredLevel":"debug"}'
前面的示例将configuredLevel
的com.example
logger 设置为DEBUG
.
设置组的日志级别
要设置 Logger 的级别,请创建一个POST
request 添加到/actuator/loggers/{group.name}
替换为 JSON 正文,该正文指定记录器组的配置级别,如以下基于 curl 的示例所示:
$ curl 'http://localhost:8080/actuator/loggers/test' -i -X POST \
-H 'Content-Type: application/json' \
-d '{"configuredLevel":"debug"}'
前面的示例将configuredLevel
的test
logger 组设置为DEBUG
.
清除日志级别
要清除 Logger 的级别,请创建一个POST
request 添加到/actuator/loggers/{logger.name}
替换为包含空对象的 JSON 正文,如以下基于 curl 的示例所示:
$ curl 'http://localhost:8080/actuator/loggers/com.example' -i -X POST \
-H 'Content-Type: application/json' \
-d '{}'
前面的示例清除了com.example
记录。