3

我使用 Apache Beam vs Kafka Clients 来处理我的数据,但是 Kafka Clients 库会产生很多消息,所以它们确实在堆栈跟踪中很混乱,我该如何更改这个包的日志级别?

依赖版本:slf4jVersion=1.7.29,apacheBeamVersion=2.18.0

我已经添加了一个文件log4j.propertiessrc/main/resources/内容如下,但它似乎不起作用

log4j.rootLogger=WARN, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.logger.org.apache.kafka.clients.consumer.internals=ERROR

构建.gradle

dependencies {
    implementation "org.apache.beam:beam-sdks-java-core:${apacheBeamVersion}"
    implementation "org.apache.beam:beam-runners-google-cloud-dataflow-java:${apacheBeamVersion}"
    implementation "org.apache.beam:beam-sdks-java-io-google-cloud-platform:${apacheBeamVersion}"
    implementation "org.apache.beam:beam-sdks-java-io-kafka:${apacheBeamVersion}"
    runtimeOnly "org.slf4j:slf4j-jdk14:${slf4jVersion}"
    ...
}

我想在我的日志中避免的日志消息:

INFO: [Consumer clientId=consumer-3, groupId=Reader-0_offset_consumer_1776081144_custom-group-group-local] Seeking to LATEST offset of partition custom-group-0
Mar 16, 2020 1:55:34 PM org.apache.kafka.clients.consumer.internals.SubscriptionState maybeSeekUnvalidated
INFO: [Consumer clientId=consumer-3, groupId=Reader-0_offset_consumer_1776081144_custom-group-group-local] Resetting offset for partition custom-group-0 to offset 9347.
Mar 16, 2020 1:55:35 PM org.apache.kafka.clients.consumer.internals.SubscriptionState lambda$requestOffsetReset$3
INFO: [Consumer clientId=consumer-3, groupId=Reader-0_offset_consumer_1776081144_custom-group-group-local] Seeking to LATEST offset of partition custom-group-0
Mar 16, 2020 1:55:35 PM org.apache.kafka.clients.consumer.internals.SubscriptionState maybeSeekUnvalidated
INFO: [Consumer clientId=consumer-3, groupId=Reader-0_offset_consumer_1776081144_custom-group-group-local] Resetting offset for partition custom-group-0 to offset 9347.
Mar 16, 2020 1:55:36 PM org.apache.kafka.clients.consumer.internals.SubscriptionState lambda$requestOffsetReset$3
INFO: [Consumer clientId=consumer-3, groupId=Reader-0_offset_consumer_1776081144_custom-group-group-local] Seeking to LATEST offset of partition custom-group-0
Mar 16, 2020 1:55:36 PM org.apache.kafka.clients.consumer.internals.SubscriptionState maybeSeekUnvalidated
INFO: [Consumer clientId=consumer-3, groupId=Reader-0_offset_consumer_1776081144_custom-group-group-local] Resetting offset for partition custom-group-0 to offset 9347.
4

1 回答 1

0

您不应该使用 slf4j-jdk14,因为它具有 java.util.logging 作为实现,并且不会考虑 log4j2 配置。所以删除这个

runtimeOnly "org.slf4j:slf4j-jdk14:${slf4jVersion}"

为了使用 log4j2 配置,您需要一个 log4j2 实现。我用了

implementation "org.apache.logging.log4j:log4j-slf4j-impl:2.13.3"

如果你想像我一样使用yaml config,只需添加这两个依赖即可

implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.10.5"
implementation "com.fasterxml.jackson.core:jackson-databind:2.10.5"

在我的例子中,我的一个传递依赖项中有另一个 slf4j 实现,我必须排除它才能使其工作。只是让你知道。

于 2020-09-30T06:48:13.273 回答