Kafka
Client Logging
Kafka Configuration
Kafka Troubleshooting
Logging Techniques

Kafka How do I enable client logging?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

For Kafka clients, “enable client logging” usually does not mean toggling one Kafka property. It usually means configuring the logging framework used by the client library so that Kafka’s internal classes emit debug information through your application logs.

For Java Clients, Logging Comes From the Logging Backend

The Java Kafka client logs through SLF4J. That means the actual log output depends on which backend your application uses, such as Logback or Log4j2.

So the usual 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

For Logback, a minimal configuration might look like this:

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>

Once that is in place, Kafka producer and consumer internals begin to show up in the application logs.

What to Log and Why

Different logger names answer different questions.

org.apache.kafka.clients is a good starting point because it covers much of the client behavior around producers, consumers, metadata refresh, retries, and group coordination.

org.apache.kafka.common.network becomes useful when you are debugging low-level connection problems.

For a quick Spring Boot setup, you can often do this 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. Only move to more verbose logging if the first pass is insufficient.

Logging a Producer Example

The following producer code does not “enable” logs by itself. It simply exercises the client so the configured logger output has something to show.

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}

If logging is configured correctly, running this code will produce both your own application output and Kafka client debug lines.

Client Logging Is Not the Same as Message Logging

Many teams say “client logging” when they actually want to log message payloads. Those are different concerns.

Kafka’s internal client logs tell you about transport and client behavior. They do not automatically log every record value your application sends or receives.

If you want application-level payload logs, add them in your producer or consumer code:

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

Be careful with this. Payload logging can leak personal data, secrets, or very large messages. Internal Kafka debug logs are usually safer than indiscriminate payload dumps.

Avoid Over-Logging in Production

Client logging is extremely useful during diagnosis, but aggressive debug logging has costs:

  • higher log volume
  • noisier troubleshooting output
  • more I/O overhead
  • possible exposure of operational details

That is why a good practice is:

  • keep normal production logging at INFO or WARN
  • temporarily enable DEBUG for Kafka packages during investigation
  • narrow the logger scope if one package is enough

Some teams also route Kafka debug logs to a separate appender so the main application log remains readable.

Non-Java Clients

The exact mechanism differs outside Java. Node, Python, Go, and librdkafka-based clients all expose logging differently. Some use standard language logging libraries. Others expose dedicated debug properties or callbacks.

So if the client is not Java, do not assume the SLF4J setup applies. The core principle still holds, though: client logging is usually controlled by the client library’s logging integration rather than by a Kafka broker property.

Common Pitfalls

The most common pitfall is looking for a Kafka producer property named “enable logging.” For Java clients, the real switch is usually the logging backend configuration.

Another mistake is turning on extremely broad debug logging and forgetting to turn it back down. That creates noisy logs and can hide the real problem.

A third issue is confusing internal client logs with payload logging. They serve different purposes and have different privacy implications.

Finally, teams sometimes debug broker-side issues without enabling client-side logs. The most useful story often comes from both ends together.

Summary

  • Kafka Java clients log through SLF4J, so you enable client logging through your logging backend.
  • Raise log levels for packages such as org.apache.kafka.clients when investigating issues.
  • Spring Boot can configure Kafka client log levels directly in application.yml.
  • Client logging helps with connection, metadata, retry, and consumer-group troubleshooting.
  • Distinguish internal client logs from application-level payload logging and use both carefully.

Course illustration
Course illustration

All Rights Reserved.