gpt4 book ai didi

java - 在 spring boot actuator 健康检查 API 中启用日志记录

转载 作者:搜寻专家 更新时间:2023-11-01 00:54:05 25 4
gpt4 key购买 nike

我正在为我的 project 使用 Spring boot Actuator API具有健康检查端点,并通过以下方式启用它:

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck

提到here

现在,当上述 /healthcheck 的状态失败时,我想在我的应用程序日志文件中启用日志,并从该端点打印整个响应。

实现这一目标的正确方法是什么?

最佳答案

最好的方法是使用 @EndpointWebExtension 扩展执行器端点.您可以执行以下操作;

@Component
@EndpointWebExtension(endpoint = HealthEndpoint.class)
public class HealthEndpointWebExtension {

private HealthEndpoint healthEndpoint;
private HealthStatusHttpMapper statusHttpMapper;

// Constructor

@ReadOperation
public WebEndpointResponse<Health> health() {
Health health = this.healthEndpoint.health();
Integer status = this.statusHttpMapper.mapStatus(health.getStatus());
// log here depending on health status.
return new WebEndpointResponse<>(health, status);
}
}

关于执行器端点扩展的更多信息 here , 4.8。扩展现有端点

关于java - 在 spring boot actuator 健康检查 API 中启用日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54977273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com