Ama*_*ngh 5 java logging spring-boot spring-boot-actuator
我正在使用Spring boot Actuator API进行运行状况检查端点,并通过以下方式启用了它:
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck
Run Code Online (Sandbox Code Playgroud)
在这里提到
现在,当上述状态/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);
}
}
Run Code Online (Sandbox Code Playgroud)
有关执行器端点扩展的更多信息,请参见4.8 。扩展现有端点
| 归档时间: |
|
| 查看次数: |
499 次 |
| 最近记录: |