Kafka: how do I enable client logging and set the log level?
Codemia Knowledge Hub ·
There is no single Kafka property that turns on client logging. The Java client logs through SLF4J, so you enable it in your logging backend (Logback, Log4j2) by raising the level of Kafka's packages, such as org.apache.kafka.clients, to DEBUG.
Configure the logging backend, not Kafka
Because the client uses SLF4J, what you see depends on the backend your application includes. The steps are:
- include a logging backend in the application
- raise the log level for Kafka packages
- reproduce the producer or consumer behavior you want to inspect
A minimal Logback configuration:
With this in place, producer and consumer internals appear in the application logs.
Which Kafka loggers to raise
org.apache.kafka.clientsis the best starting point. It covers much of the producer and consumer behavior: metadata refresh, retries and group coordination.org.apache.kafka.common.networkhelps with low-level connection problems.
In Spring Boot, you can set the levels in application.yml:
That is often enough to diagnose:
- failed broker connections
- consumer group rebalance behavior
- offset commit problems
- metadata lookup issues
- retry and timeout behavior
Start with DEBUG and go more verbose only if that is not enough.
A producer to generate log output
This code does not enable logging by itself. It just exercises the client so the configured loggers have something to print.
With logging configured, running it prints your own output plus Kafka client debug lines.
Client logs do not include message payloads
Kafka's internal client logs describe transport and client behavior. They do not log the record values your application sends or receives. If you want payload logs, add them in your own producer or consumer code:
Be careful: payload logging can leak personal data or secrets, or flood logs with very large messages. Kafka's internal debug logs are usually safer than dumping every payload.
Keeping debug logging out of production
Debug logging is useful during diagnosis but has costs:
- higher log volume
- noisier troubleshooting output
- more I/O overhead
- possible exposure of operational details
So:
- keep normal production logging at
INFOorWARN - enable
DEBUGfor Kafka packages temporarily while investigating - narrow the logger scope if one package is enough
Some teams route Kafka debug logs to a separate appender so the main application log stays readable. Remember to turn broad debug logging back down afterwards, or the noise can hide the real problem.
Non-Java clients
Node, Python, Go and librdkafka-based clients each expose logging differently. Some use the language's standard logging library; others have dedicated debug properties or callbacks. The SLF4J setup does not apply to them, but the principle does: client logging is controlled by the client library's logging integration, not by a broker property.
When debugging, also collect broker-side logs alongside client logs. The full picture often comes from both ends together.
Related reading
- Kafka How to connect kafka-console-consumer to fetch remote broker topic content?
- Kafka How to consume data based on Timestamp
- Kafka how to consume one topic parallel
- Kafka How to delete records from a topic using Java API?
- Kafka Monitoring JMX Attributes Count or MeanRate?
- Kafka on Kubernetes multi-node
- Kafka ignoring `transaction.timeout.ms` for producer
- Kafka inaccessible once inside Kubernetes/Minikube
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.