[英]How to configure logging for Kafka producers?
I am using Kafka producer client and i don't have any log4j configuration in my project.我正在使用 Kafka 生产者客户端,我的项目中没有任何 log4j 配置。
On running, the program prints a lot of Kafka Debug logs which i really don't want.在运行时,程序会打印很多我真的不想要的 Kafka 调试日志。
So, i tried to add a log4j.properties to set log level to ERROR as below which does not seem to work:因此,我尝试添加一个 log4j.properties 以将日志级别设置为 ERROR,如下所示,这似乎不起作用:
log4j.rootLogger=ERROR
How do i change Kafka Log Level?如何更改 Kafka 日志级别?
Use the command line flag -Dlog4j.configuration=file:/path/to/log4j.properties
when running your client.运行客户端时使用命令行标志-Dlog4j.configuration=file:/path/to/log4j.properties
。
Example log4j property files:示例 log4j 属性文件:
For mirror maker and other tools that result in a call to kafka-run-class.sh
, you can use the env variable KAFKA_LOG4J_OPTS
(set to something like -Dlog4j.configuration=file:/path/to/log4j.properties
) to change the logging configuration.对于导致调用kafka-run-class.sh
镜像制造商和其他工具,您可以使用环境变量KAFKA_LOG4J_OPTS
(设置为-Dlog4j.configuration=file:/path/to/log4j.properties
)进行更改日志配置。 See: https://github.com/apache/kafka/blob/0.10.2/bin/kafka-run-class.sh#L158参见: https : //github.com/apache/kafka/blob/0.10.2/bin/kafka-run-class.sh#L158
Example of my log4j.properties
file for mirror maker that I use for testing.我用于测试的镜像制造商的log4j.properties
文件示例。
# 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
Try adding logging.level.org.apache.kafka: DEBUG into your clients configuration properties.尝试将 logging.level.org.apache.kafka: DEBUG 添加到您的客户端配置属性中。 I am using Springboot and this is the format.我正在使用 Springboot,这是格式。 Use appropriate format for your clients program.为您的客户程序使用适当的格式。
org.apache.log4j.Logger.getLogger("org").setLevel(Level.WARN);
org.apache.log4j.Logger.getLogger("akka").setLevel(Level.WARN);
org.apache.log4j.Logger.getLogger("kafka").setLevel(Level.WARN);
Define the logging level as below in application.yml
file or your properties file.在application.yml
文件或您的属性文件中定义日志级别如下。
logging:
level:
root: INFO
org:
apache:
kafka: WARN
By defining the above, Kafka will print out only the warnings logs.通过以上定义,Kafka 将只打印警告日志。
I assumed you were talking about Kafka server logs.我以为你在谈论 Kafka 服务器日志。 You can change log level to ERROR using following config您可以使用以下配置将日志级别更改为 ERROR
log4j.logger.kafka=ERROR, kafkaAppender
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.