来自Kafka Producer的过多控制台消息

时间:2016-02-10 02:02:53

标签: log4j apache-kafka kafka-producer-api

如何控制Kafka Producer或Consumer的控制台日志记录级别?我在Scala中使用Kafka 0.9 API。

每次调用send KafkaProducer时,控制台都会提供如下输出。这是否表示我没有正确设置KafkaProducer,而不仅仅是过度记录的问题?

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

Kafka服务器和Zookeeper查看的properties文件中有日志配置,但我认为这些配置不会影响Kafka客户端。更改这些文件中的某些日志记录配置,并重新启动Kafka服务器和Zookeeper以便重新加载这些文件,但仍未解决问题。

谢谢

3 个答案:

答案 0 :(得分:2)

将此添加到您的客户端代码中。

      Logger.getLogger("org").setLevel(Level.WARNING);
      Logger.getLogger("akka").setLevel(Level.WARNING);       
      Logger.getLogger("kafka").setLevel(Level.WARNING);

答案 1 :(得分:2)

在logback.xml上添加名为org.apacha.kafka的记录器

<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>

答案 2 :(得分:0)

正确配置logback解决了我的问题: http://www.mkyong.com/logging/logback-xml-example/