Chapter 12. 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. 12.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 export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/log4j.properties"; \ ./bin/kafka-server-start.sh \ ./config/server.properties Passing the name and location of the logging properties file used by ZooKeeper export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/log4j.properties"; \ ./bin/zookeeper-server-start.sh -daemon \ ./config/zookeeper.properties Passing the name and location of the logging properties file used by Kafka Connect export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/connect-log4j.properties"; \ ./bin/connect-distributed.sh \ ./config/connect-distributed.properties Passing the name and location of the logging properties file used by MirrorMaker 2 export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/connect-log4j.properties"; \ ./bin/connect-mirror-maker.sh \ ./config/connect-mirror-maker.properties 12.2. Dynamically change logging levels for Kafka broker loggers 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. Prerequisites Streams for Apache Kafka is installed on each host , and the configuration files are available. Kafka is running . Procedure List all the broker loggers for a broker by using the kafka-configs.sh tool: ./bin/kafka-configs.sh --bootstrap-server <broker_address> --describe --entity-type broker-loggers --entity-name <broker_id> For example, for broker 0 : ./bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type broker-loggers --entity-name 0 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={} 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. ./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> For example, for broker 0 : ./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 If successful this returns: Completed updating config for broker: 0. 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: ./bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter --delete-config " LOGGER-ONE , LOGGER-TWO " --entity-type broker-loggers --entity-name <broker_id> Additional resources Updating Broker Configs in the Apache Kafka documentation 12.3. Dynamically change logging levels for Kafka Connect and MirrorMaker 2 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 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= Prerequisites Streams for Apache Kafka is installed on each host , and the configuration files are available. Kafka is running . Kafka Connect or MirrorMaker 2 is running. Procedure Check the current logging level for the loggers configured in the connect-log4j.properties file: USD cat ./config/connect-log4j.properties # ... log4j.rootLogger=INFO, stdout, connectAppender # ... log4j.logger.org.reflections=ERROR 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.reflections": { "level": "ERROR" }, "root": { "level": "INFO" } } 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" } 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" } } If you change the root logger, the logging level for loggers that used the root logging level by default are also changed.

Commands:
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/log4j.properties"; ./bin/kafka-server-start.sh ./config/server.properties
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/log4j.properties"; ./bin/zookeeper-server-start.sh -daemon ./config/zookeeper.properties
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/connect-log4j.properties"; ./bin/connect-distributed.sh ./config/connect-distributed.properties
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/my/path/to/connect-log4j.properties"; ./bin/connect-mirror-maker.sh ./config/connect-mirror-maker.properties
./bin/kafka-configs.sh --bootstrap-server <broker_address> --describe --entity-type broker-loggers --entity-name <broker_id>
./bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type broker-loggers --entity-name 0
# kafka.controller.ControllerChannelManager=INFO sensitive=false synonyms={} kafka.log.TimeIndex=INFO sensitive=false synonyms={}
./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>
./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
Completed updating config for broker: 0.
./bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter --delete-config " LOGGER-ONE , LOGGER-TWO " --entity-type broker-loggers --entity-name <broker_id>
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
admin.listeners=
cat ./config/connect-log4j.properties log4j.rootLogger=INFO, stdout, connectAppender log4j.logger.org.reflections=ERROR
curl -s http://localhost:8083/admin/loggers/ | jq { "org.reflections": { "level": "ERROR" }, "root": { "level": "INFO" } }
curl -s http://localhost:8083/admin/loggers/org.apache.kafka.connect.mirror.MirrorCheckpointConnector | jq { "level": "INFO" }
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" } }