Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kafka: How do I enable client logging?

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?

like image 363
Mark Harrison Avatar asked Jan 27 '16 17:01

Mark Harrison


People also ask

Can Kafka be used for logging?

Kafka can serve as a kind of external commit-log for a distributed system. The log helps replicate data between nodes and acts as a re-syncing mechanism for failed nodes to restore their data. The log compaction feature in Kafka helps support this usage. In this usage Kafka is similar to Apache BookKeeper project.

How do I change the log level in Kafka?

Change the log level for a specific logger Enter the following command to change the log level from DEBUG to TRACE for the WorkerSourceTask logger: curl -s -X PUT -H "Content-Type:application/json" \ http://localhost:8083/admin/loggers/org.apache.kafka.connect.runtime.WorkerSourceTask \ -d '{"level": "TRACE"}' | jq '.

What is Kafka logging?

Introduction to Logs in Apache Kafka Apache Kafka logs are a collection of various data segments present on your disk, having a name as that of a form-topic partition or any specific topic-partition. Each Kafka log provides a logical representation of a unique topic-based partitioning.

How do I get Kafka logs?

If you open script kafka-server-start or /usr/bin/zookeeper-server-start , you will see at the bottom that it calls kafka-run-class script. And you will see there that it uses LOG_DIR as the folder for the logs of the service (not to be confused with kafka topics data). Show activity on this post.


1 Answers

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.

like image 69
Mark Harrison Avatar answered Nov 11 '22 10:11

Mark Harrison