Kafka: How do I enable client logging?

2020-07-08 06:43发布

When I instantiate a Kafka consumer

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条回答
乱世女痞
2楼-- · 2020-07-08 07:15

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.

查看更多
登录 后发表回答