日志记录器 (loggers
)
loggers
端点用于访问应用的日志记录器及其级别配置。
获取所有日志记录器
要获取应用的所有日志记录器,请对 /actuator/loggers
发起 GET
请求,示例如下:
$ 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" ]
}
}
}
响应结构
响应内容包含应用日志记录器的详细信息。 下表描述了响应结构:
Path | Type | Description |
---|---|---|
|
|
Levels support by the logging system. |
|
|
Loggers keyed by name. |
|
|
Logger groups keyed by name |
|
|
Configured level of the logger, if any. |
|
|
Effective level of the logger. |
|
|
Configured level of the logger group, if any. |
|
|
Loggers that are part of this group |
获取单个日志记录器
要获取单个日志记录器,请对 /actuator/loggers/{logger.name}
发起 GET
请求,示例如下:
$ 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 '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 请求体中指定该日志记录器的 configuredLevel,示例如下:
$ curl 'http://localhost:8080/actuator/loggers/com.example' -i -X POST \
-H 'Content-Type: application/json' \
-d '{"configuredLevel":"debug"}'
上述示例将 com.example
日志记录器的 configuredLevel
设置为 DEBUG
。