SpringBoot 3应用程序中MicroMeter LoggingMeterRegistry配置

问题描述 投票:0回答:1

我正在编写一个 SpringBoot 3 应用程序,它也需要报告日志文件中的指标。

我通过以下方式注册了

io.micrometer.core.instrument.logging.LoggingMeterRegistry
的实例:

@Bean
LoggingMeterRegistry loggingMeterRegistry() {
    return new LoggingMeterRegistry();
}

它按预期工作,但是:

  1. 我不知道如何通过
    step
    文件提供配置设置(如
    application.yaml
    )。
  2. 我不知道如何注册类的自定义实例
    com.codahale.metrics.MetricFilter
    来过滤输出。

有人可以告诉我如何实现这些目标吗?

提前非常感谢!

编辑:我的问题似乎类似于如何在 Spring Boot 2.x 中配置 LoggingMeterRegistry 步骤持续时间? .

java spring-boot metrics micrometer spring-micrometer
1个回答
0
投票

这是我针对第一个问题的非常干净的解决方法“我不知道如何通过 application.yaml 文件提供配置设置(如步骤)”(经过大量调试

LoggingMeterRegistry
后发现)。

配置类

@Bean
LoggingMeterRegistry loggingMeterRegistry(Environment environments) {
    LoggingRegistryConfig config =
        key ->
            key.equals("logging.step")
          ? environments.getProperty("management.metrics.export.logging.step")
          : null;

    return new LoggingMeterRegistry(config, Clock.SYSTEM);
}

application.yaml

management:
  metrics:
    export:
      logging:
        step: 10s

现在,我要为第二个问题找到解决方案......

© www.soinside.com 2019 - 2024. All rights reserved.