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?
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.
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 '.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With