Kafka
Client Logging
Kafka Configuration
Kafka Troubleshooting
Logging Techniques

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:

  1. include a logging backend in the application
  2. raise the log level for Kafka packages
  3. reproduce the producer or consumer behavior you want to inspect

A minimal Logback configuration:

xml
1<configuration>
2  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3    <encoder>
4      <pattern>%d %-5level %logger - %msg%n</pattern>
5    </encoder>
6  </appender>
7
8  <logger name="org.apache.kafka.clients" level="DEBUG"/>
9  <logger name="org.apache.kafka.common.network" level="DEBUG"/>
10
11  <root level="INFO">
12    <appender-ref ref="STDOUT"/>
13  </root>
14</configuration>

With this in place, producer and consumer internals appear in the application logs.

Which Kafka loggers to raise

  • org.apache.kafka.clients is the best starting point. It covers much of the producer and consumer behavior: metadata refresh, retries and group coordination.
  • org.apache.kafka.common.network helps with low-level connection problems.

In Spring Boot, you can set the levels in application.yml:

yaml
1logging:
2  level:
3    org.apache.kafka.clients: DEBUG
4    org.apache.kafka.common.network: DEBUG

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.

java
1import org.apache.kafka.clients.producer.KafkaProducer;
2import org.apache.kafka.clients.producer.ProducerRecord;
3
4import java.util.Properties;
5
6public class ProducerDemo {
7    public static void main(String[] args) {
8        Properties props = new Properties();
9        props.put("bootstrap.servers", "localhost:9092");
10        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
11        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
12
13        try (KafkaProducer<String, String> producer = new KafkaProducer<>(props)) {
14            producer.send(new ProducerRecord<>("orders", "key-1", "created"));
15            producer.flush();
16        }
17    }
18}

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:

java
consumerRecords.forEach(record ->
        System.out.println("topic=" + record.topic() + " value=" + record.value()));

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 INFO or WARN
  • enable DEBUG for 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.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design