如何为Kafka生产者配置日志记录? [英] How to configure logging for Kafka producers?

查看:882
本文介绍了如何为Kafka生产者配置日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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
    • 由镜像制作器之类的工具使用,实际上只是stdout
    • 被kafka服务器之类的工具使用

    对于导致调用kafka-run-class.sh的镜像制造商和其他工具,可以使用env变量KAFKA_LOG4J_OPTS(设置为类似-Dlog4j.configuration=file:/path/to/log4j.properties的值)来更改日志记录配置.参见: https://github.com /apache/kafka/blob/0.10.2/bin/kafka-run-class.sh#L158

    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. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆