Chapter 10. Configuring logging for Kafka components


Configure the logging levels of Kafka components directly in the configuration properties. You can also change the broker levels dynamically for Kafka brokers, Kafka Connect, and MirrorMaker 2.

Increasing the log level detail, such as from INFO to DEBUG, can aid in troubleshooting a Kafka cluster. However, more verbose logs may also negatively impact performance and make it more difficult to diagnose issues.

10.1. Configuring Kafka logging properties

Kafka components use the Log4j framework for error logging. By default, logging configuration is read from the classpath or config directory using the following properties files:

  • log4j.properties for Kafka and ZooKeeper
  • connect-log4j.properties for Kafka Connect and MirrorMaker 2

If they are not set explicitly, loggers inherit the log4j.rootLogger logging level configuration in each file. You can change the logging level in these files. You can also add and set logging levels for other loggers.

You can change the location and name of logging properties file using the KAFKA_LOG4J_OPTS environment variable, which is used by the start script for the component.

Passing the name and location of the logging properties file used by Kafka brokers

su - kafka
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/log4j.properties"; \
/opt/kafka/bin/kafka-server-start.sh \
/opt/kafka/config/server.properties
Copy to Clipboard Toggle word wrap

Passing the name and location of the logging properties file used by ZooKeeper

su - kafka
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/log4j.properties"; \
/opt/kafka/bin/zookeeper-server-start.sh -daemon \
/opt/kafka/config/zookeeper.properties
Copy to Clipboard Toggle word wrap

Passing the name and location of the logging properties file used by Kafka Connect

su - kafka
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/connect-log4j.properties"; \
/opt/kafka/bin/connect-distributed.sh \
/opt/kafka/config/connect-distributed.properties
Copy to Clipboard Toggle word wrap

Passing the name and location of the logging properties file used by MirrorMaker 2

su - kafka
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/connect-log4j.properties"; \
/opt/kafka/bin/connect-mirror-maker.sh \
/opt/kafka/config/connect-mirror-maker.properties
Copy to Clipboard Toggle word wrap

Kafka broker logging is provided by broker loggers in each broker. Dynamically change the logging level for broker loggers at runtime without having to restart the broker.

You can also reset broker loggers dynamically to their default logging levels.

Procedure

  1. Switch to the kafka user:

    su - kafka
    Copy to Clipboard Toggle word wrap
  2. List all the broker loggers for a broker by using the kafka-configs.sh tool:

    /opt/kafka/bin/kafka-configs.sh --bootstrap-server <broker_address> --describe --entity-type broker-loggers --entity-name BROKER-ID
    Copy to Clipboard Toggle word wrap

    For example, for broker 0:

    /opt/kafka/bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type broker-loggers --entity-name 0
    Copy to Clipboard Toggle word wrap

    This returns the logging level for each logger: TRACE, DEBUG, INFO, WARN, ERROR, or FATAL.

    For example:

    #...
    kafka.controller.ControllerChannelManager=INFO sensitive=false synonyms={}
    kafka.log.TimeIndex=INFO sensitive=false synonyms={}
    Copy to Clipboard Toggle word wrap
  3. Change the logging level for one or more broker loggers. Use the --alter and --add-config options and specify each logger and its level as a comma-separated list in double quotes.

    /opt/kafka/bin/kafka-configs.sh --bootstrap-server <broker_address> --alter --add-config "LOGGER-ONE=NEW-LEVEL,LOGGER-TWO=NEW-LEVEL" --entity-type broker-loggers --entity-name BROKER-ID
    Copy to Clipboard Toggle word wrap

    For example, for broker 0:

    /opt/kafka/bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter --add-config "kafka.controller.ControllerChannelManager=WARN,kafka.log.TimeIndex=WARN" --entity-type broker-loggers --entity-name 0
    Copy to Clipboard Toggle word wrap

    If successful this returns:

    Completed updating config for broker: 0.
    Copy to Clipboard Toggle word wrap

Resetting a broker logger

You can reset one or more broker loggers to their default logging levels by using the kafka-configs.sh tool. Use the --alter and --delete-config options and specify each broker logger as a comma-separated list in double quotes:

/opt/kafka/bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter --delete-config "LOGGER-ONE,LOGGER-TWO" --entity-type broker-loggers --entity-name BROKER-ID
Copy to Clipboard Toggle word wrap

Dynamically change logging levels for Kafka Connect workers or MirrorMaker 2 connectors at runtime without having to restart.

Use the Kafka Connect API to change the log level temporarily for a worker or connector logger. The Kafka Connect API provides an admin/loggers endpoint to get or modify logging levels. When you change the log level using the API, the logger configuration in the connect-log4j.properties configuration file does not change. If required, you can permanently change the logging levels in the configuration file.

Note

You can only change the logging level of MirrorMaker 2 at runtime when in distributed or standalone mode. Dedicated MirrorMaker 2 clusters have no Kafka Connect REST API, so changing the logging level is not possible.

The default listener for the Kafka Connect API is on port 8083, which is used in this procedure. You can change or add more listeners, and also enable TLS authentication, using admin.listeners configuration.

Example listener configuration for the admin endpoint

admin.listeners=https://localhost:8083
admin.listeners.https.ssl.truststore.location=/path/to/truststore.jks
admin.listeners.https.ssl.truststore.password=123456
admin.listeners.https.ssl.keystore.location=/path/to/keystore.jks
admin.listeners.https.ssl.keystore.password=123456
Copy to Clipboard Toggle word wrap

If you do not want the admin endpoint to be available, you can disable it in the configuration by specifying an empty string.

Example listener configuration to disable the admin endpoint

admin.listeners=
Copy to Clipboard Toggle word wrap

Prerequisites

Procedure

  1. Switch to the kafka user:

    su - kafka
    Copy to Clipboard Toggle word wrap
  2. Check the current logging level for the loggers configured in the connect-log4j.properties file:

    $ cat /opt/kafka/config/connect-log4j.properties
    
    # ...
    log4j.rootLogger=INFO, stdout, connectAppender
    # ...
    log4j.logger.org.apache.zookeeper=ERROR
    log4j.logger.org.reflections=ERROR
    Copy to Clipboard Toggle word wrap

    Use a curl command to check the logging levels from the admin/loggers endpoint of the Kafka Connect API:

    curl -s http://localhost:8083/admin/loggers/ | jq
    
    {
      "org.apache.zookeeper": {
        "level": "ERROR"
      },
      "org.reflections": {
        "level": "ERROR"
      },
      "root": {
        "level": "INFO"
      }
    }
    Copy to Clipboard Toggle word wrap

    jq prints the output in JSON format. The list shows standard org and root level loggers, plus any specific loggers with modified logging levels.

    If you configure TLS (Transport Layer Security) authentication for the admin.listeners configuration in Kafka Connect, then the address of the loggers endpoint is the value specified for admin.listeners with the protocol as https, such as https://localhost:8083.

    You can also get the log level of a specific logger:

    curl -s http://localhost:8083/admin/loggers/org.apache.kafka.connect.mirror.MirrorCheckpointConnector | jq
    
    {
      "level": "INFO"
    }
    Copy to Clipboard Toggle word wrap
  3. Use a PUT method to change the log level for a logger:

    curl -Ss -X PUT -H 'Content-Type: application/json' -d '{"level": "TRACE"}' http://localhost:8083/admin/loggers/root
    
    {
      # ...
    
      "org.reflections": {
        "level": "TRACE"
      },
      "org.reflections.Reflections": {
        "level": "TRACE"
      },
      "root": {
        "level": "TRACE"
      }
    }
    Copy to Clipboard Toggle word wrap

    If you change the root logger, the logging level for loggers that used the root logging level by default are also changed.

Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat