このコンテンツは選択した言語では利用できません。

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

Procedure

  1. 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={}
  2. 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

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

Procedure

  1. Check the current logging level for the loggers configured in the connect-log4j.properties file:

    $ 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"
    }
  2. 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.

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.