Excessive console messages from Kafka Producer

2019-07-19 04:32发布

How do you control the console logging level of a Kafka Producer or Consumer? I am using the Kafka 0.9 API in Scala.

Every time send on the KafkaProducer is called, the console gives output like below. Could this indicate I do not have the KafkaProducer set up correctly, rather than just an issue of excessive logging?

17:52:21.236 [pool-10-thread-7] INFO  o.a.k.c.producer.ProducerConfig - ProducerConfig values: 
compression.type = none
metric.reporters = []
metadata.max.age.ms = 300000
.
.
.
17:52:21.279 [pool-10-thread-7] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name bufferpool-wait-time
17:52:21.280 [pool-10-thread-7] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name buffer-exhausted-records
17:52:21.369 [pool-10-thread-7] DEBUG org.apache.kafka.clients.Metadata - Updated cluster metadata version 1 to Cluster(nodes = [Node(-1, localhost, 9092)], partitions = [])
17:52:21.369 [pool-10-thread-7] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name connections-closed:client-id-producer-2
17:52:21.369 [pool-10-thread-7] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name connections-created:client-id-producer-2
17:52:21.370 [pool-10-thread-7] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name bytes-sent-received:client-id-producer-2
17:52:21.370 [pool-10-thread-7] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name bytes-sent:client-id-producer-2
.
.

There are logging configurations in the properties files the Kafka server and Zookeeper look at, but I've assumed these do not affect Kafka clients. Changing some of the logging configurations in these files, and restarting the Kafka server and Zookeeper so those files are reloaded, has not solved the problem.

Thank you

3条回答
ら.Afraid
2楼-- · 2019-07-19 04:35

Add this to your client code.

      Logger.getLogger("org").setLevel(Level.WARNING);
      Logger.getLogger("akka").setLevel(Level.WARNING);       
      Logger.getLogger("kafka").setLevel(Level.WARNING);
查看更多
该账号已被封号
3楼-- · 2019-07-19 04:47

Correctly configuring logback solved my problem: http://www.mkyong.com/logging/logback-xml-example/

查看更多
forever°为你锁心
4楼-- · 2019-07-19 04:48

add logger with name org.apacha.kafka on your logback.xml

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>
            %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
        </Pattern>
    </layout>
</appender>

<logger name="org.apache.kafka" level="warn">
    <appender-ref ref="STDOUT" />
</logger>


<root level="info">
    <appender-ref ref="STDOUT" />
</root>

查看更多
登录 后发表回答