如何为 Kafka 生产者配置日志记录? [英] How to configure logging for Kafka producers?
问题描述
我正在使用 Kafka 生产者客户端,我的项目中没有任何 log4j 配置.
I am using Kafka producer client and i don't have any log4j configuration in my project.
在运行时,程序打印了很多我真的不想要的 Kafka 调试日志.
On running, the program prints a lot of Kafka Debug logs which i really don't want.
因此,我尝试添加 log4j.properties 以将日志级别设置为 ERROR,如下所示,这似乎不起作用:
So, i tried to add a log4j.properties to set log level to ERROR as below which does not seem to work:
log4j.rootLogger=ERROR
如何更改 Kafka 日志级别?
How do i change Kafka Log Level?
推荐答案
在运行客户端时使用命令行标志 -Dlog4j.configuration=file:/path/to/log4j.properties
.
Use the command line flag -Dlog4j.configuration=file:/path/to/log4j.properties
when running your client.
示例 log4j 属性文件:
Example log4j property files:
- https://github.com/apache/kafka/blob/trunk/config/tools-log4j.properties
- 被镜子制造商等工具使用,实际上只是标准输出
- 被 kafka 服务器等工具使用
对于导致调用
kafka-run-class.sh
的镜像制造商和其他工具,您可以使用环境变量KAFKA_LOG4J_OPTS
(设置为类似-Dlog4j.configuration=file:/path/to/log4j.properties
) 更改日志配置.请参阅:https://github.com/apache/kafka/blob/0.10.2/bin/kafka-run-class.sh#L158For mirror maker and other tools that result in a call to
kafka-run-class.sh
, you can use the env variableKAFKA_LOG4J_OPTS
(set to something like-Dlog4j.configuration=file:/path/to/log4j.properties
) to change the logging configuration. See: https://github.com/apache/kafka/blob/0.10.2/bin/kafka-run-class.sh#L158我用于测试的镜像制造商的
log4j.properties
文件示例.Example of my
log4j.properties
file for mirror maker that I use for testing.# https://github.com/apache/kafka/blob/trunk/config/tools-log4j.properties log4j.rootLogger=DEBUG, stderr log4j.appender.stderr=org.apache.log4j.ConsoleAppender log4j.appender.stderr.layout=org.apache.log4j.PatternLayout log4j.appender.stderr.layout.ConversionPattern=[%d] %p %m (%c)%n log4j.appender.stderr.Target=System.err
这篇关于如何为 Kafka 生产者配置日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!