我使用Apache Beam与Kafka Clients来处理我的数据,但库Kafka Client会产生很多消息,所以它们在堆栈跟踪中确实很混乱,我如何更改此包的日志级别?
依赖项的版本:slf4jVersion=1.7.29
、apacheBeamVersion=2.18.0
我已经添加了一个文件log4j.properties
到src/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
build.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.
您不应该使用slf4j-jdk14,因为它有java.util.logging作为实现,并且不会考虑log4j2配置。所以删除这个
runtimeOnly "org.slf4j:slf4j-jdk14:${slf4jVersion}"
为了使用log4j2-config,您将需要一个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实现,我必须排除它才能工作。只是让你知道。