日志记录器(loggers

loggers 端点提供对应用程序日志记录器及其日志级别配置的访问。spring-doc.cadn.net.cn

检索所有日志记录器

要获取应用程序的日志记录器,请向 GET 发送一个 /actuator/loggers 请求,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

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

生成的响应类似于以下内容:spring-doc.cadn.net.cn

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

响应结构

响应包含应用程序日志记录器的详细信息。 下表描述了响应的结构:spring-doc.cadn.net.cn

路径 类型 <description> </description>

levelsspring-doc.cadn.net.cn

Arrayspring-doc.cadn.net.cn

日志系统支持的日志级别。spring-doc.cadn.net.cn

loggersspring-doc.cadn.net.cn

Objectspring-doc.cadn.net.cn

按名称作为键的记录器。spring-doc.cadn.net.cn

groupsspring-doc.cadn.net.cn

Objectspring-doc.cadn.net.cn

按名称分组的记录器spring-doc.cadn.net.cn

loggers.*.configuredLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

已配置的日志记录器级别(如果有的话)。spring-doc.cadn.net.cn

loggers.*.effectiveLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

日志记录器的有效级别。spring-doc.cadn.net.cn

groups.*.configuredLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

已配置的日志记录器组的级别(如果有的话)。spring-doc.cadn.net.cn

groups.*.membersspring-doc.cadn.net.cn

Arrayspring-doc.cadn.net.cn

属于此组的日志记录器spring-doc.cadn.net.cn

获取单个 Logger

要获取单个日志记录器,请向 GET 发送一个 /actuator/loggers/{logger.name} 请求,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

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

前面的示例检索了名为 com.example 的日志记录器的相关信息。 返回的结果类似于以下内容:spring-doc.cadn.net.cn

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

响应结构

响应包含所请求的日志记录器的详细信息。 下表描述了响应的结构:spring-doc.cadn.net.cn

路径 类型 <description> </description>

configuredLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

已配置的日志记录器级别(如果有的话)。spring-doc.cadn.net.cn

effectiveLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

日志记录器的有效级别。spring-doc.cadn.net.cn

检索单个组

要检索单个日志组,请向 GET 发起一个 /actuator/loggers/{group.name} 请求,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

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

前面的示例检索名为 test 的日志记录器组的相关信息。 返回的响应类似于以下内容:spring-doc.cadn.net.cn

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 82

{
  "configuredLevel" : "INFO",
  "members" : [ "test.member1", "test.member2" ]
}

响应结构

响应包含所请求组的详细信息。 下表描述了响应的结构:spring-doc.cadn.net.cn

路径 类型 <description> </description>

configuredLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

已配置的日志记录器组的级别(如果有的话)。spring-doc.cadn.net.cn

membersspring-doc.cadn.net.cn

Arrayspring-doc.cadn.net.cn

属于此组的日志记录器spring-doc.cadn.net.cn

设置日志级别

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

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

前面的示例将 configuredLevel 记录器的 com.example 设置为 DEBUGspring-doc.cadn.net.cn

请求结构

该请求指定了日志记录器所需的日志级别。 下表描述了请求的结构:spring-doc.cadn.net.cn

路径 类型 <description> </description>

configuredLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

记录器的日志级别。可省略以清除该级别。spring-doc.cadn.net.cn

为组设置日志级别

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

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

前面的示例将 configuredLevel 日志记录器组的 test 设置为 DEBUGspring-doc.cadn.net.cn

请求结构

请求指定了日志记录器组所需的日志级别。 下表描述了请求的结构:spring-doc.cadn.net.cn

路径 类型 <description> </description>

configuredLevelspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

记录器的日志级别。可省略以清除该级别。spring-doc.cadn.net.cn

清除日志级别

要清除某个日志记录器的级别,请向 POST 发送一个 /actuator/loggers/{logger.name} 请求,并在请求体中包含一个空的 JSON 对象,如下列基于 curl 的示例所示:spring-doc.cadn.net.cn

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

前面的示例清除了为 com.example 日志记录器配置的日志级别。spring-doc.cadn.net.cn