|
此版本仍在开发中,尚未被视为稳定版本。如需最新稳定版本,请使用 Spring Boot 4.0.4! |
日志记录器 (loggers)
loggers 端点提供对应用程序日志记录器及其级别配置的访问。
检索所有日志记录器
要检索应用程序的日志记录器,向 /actuator/loggers 发送一个 GET 请求,如以下基于 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" ]
}
}
}
检索单个 Logger
要检索单个日志记录器,向 /actuator/loggers/{logger.name} 发送一个 GET 请求,如以下基于 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"
}
检索单个组
要检索单个组,向 /actuator/loggers/{group.name} 发送 GET 请求,如以下基于 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" ]
}
设置日志级别
要设置日志记录器的级别,向 /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"}'
前面的示例将日志记录器 com.example 的 configuredLevel 设置为 DEBUG。
为组设置日志级别
要设置日志记录器的级别,向 /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"}'
前面的示例将 test 日志组的 configuredLevel 设置为 DEBUG。
清除日志级别
要清除日志记录器的级别,向 /actuator/loggers/{logger.name} 发送一个包含空对象的 JSON 正文的 POST 请求,如以下基于 curl 的示例所示:
$ curl 'http://localhost:8080/actuator/loggers/com.example' -i -X POST \
-H 'Content-Type: application/json' \
-d '{}'
前面的示例清除了 com.example 记录器的配置级别。