[英]How to send count of log messages to Graphite using Log4j?
I am trying to use this module https://metrics.dropwizard.io/4.1.2/manual/log4j.html , in order to have counters in Graphite for the number of warning and error messages that are logged.我正在尝试使用此模块https://metrics.dropwizard.io/4.1.2/manual/log4j.html ,以便在 Graphite 中使用计数器记录警告和错误消息的数量。
Anyway, when I add the needed dependency, and use the prescribed log4j configuration as per the documentation https://metrics.dropwizard.io/4.1.2/manual/log4j.html , I get the following errors when I run my application locally:无论如何,当我添加所需的依赖项,并按照文档https://metrics.dropwizard.io/4.1.2/manual/log4j.html使用规定的 log4j 配置时,当我在本地运行我的应用程序时出现以下错误:
2020-03-31 11:34:28,706 main ERROR Appenders contains an invalid element or attribute "MetricsAppender"
2020-03-31 11:34:28,716 main ERROR Unable to locate appender "metricsAppender" for logger config "root"
I use the following configuration:我使用以下配置:
<Configuration status="INFO" name="log4j2-config" packages="com.codahale.metrics.log4j2">
<Appenders>
<MetricsAppender name="metrics" registryName="shared-metrics-registry"/>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="metrics" />
</Root>
</Loggers>
</Configuration>
I have the metrics-log4j dependency added to my POM, as the following:我将 metrics-log4j 依赖项添加到我的 POM 中,如下所示:
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-log4j</artifactId>
<version>3.2.6</version>
</dependency>
<dependency>
My working environment: Spring Boot 2 + Maven + Java 11我的工作环境:Spring Boot 2 + Maven + Java 11
How to overcome these errors?如何克服这些错误?
您使用的是 Log4J 2,但您使用的指标库是用于 Log4J 1 的。尝试使用Dropwizard 指标用于 Log4J 2 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.