Kafka:如何启用客户端日志记录? [英] Kafka: How do I enable client logging?

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

问题描述

当我实例化一个 Kafka 消费者时

When I instantiate a Kafka consumer

KafkaConsumer<String,String> consumer = new KafkaConsumer<String,String>(props);

我收到这条消息

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

如何为我的客户端程序启用日志记录?

How do I enable logging for my client program?

推荐答案

将此属性文件 src/main/resources/log4j.properties 添加到您的项目中:

Add this property file src/main/resources/log4j.properties to your project:

$ cat src/main/resources/log4j.properties 
# Root logger option
log4j.rootLogger=DEBUG, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

这将启用日志记录.然后您可以设置标准选项例如调试级别、输出格式等,根据日志记录文档.

This will enable logging. You can then set the standard options such as debug level, output format, etc, as per the logging documentation.

这篇关于Kafka:如何启用客户端日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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