Kafka:如何启用客户端日志记录?

时间:2022-04-14 22:56:14

When I instantiate a Kafka consumer

当我实例化Kafka消费者时

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

I get this message

我收到这条消息

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?

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

1 个解决方案

#1


9  

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

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

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

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

#1


9  

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

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

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

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