4

I am running locally Kafka using the confluentinc/cp-kafka Docker image and I am setting the following logging container environment variables:

KAFKA_LOG4J_ROOT_LOGLEVEL: ERROR
KAFKA_LOG4J_LOGGERS: >-
    org.apache.zookeeper=ERROR,
    org.apache.kafka=ERROR,
    kafka=ERROR,
    kafka.cluster=ERROR,
    kafka.controller=ERROR,
    kafka.coordinator=ERROR,
    kafka.log=ERROR,
    kafka.server=ERROR,
    kafka.zookeeper=ERROR,
    state.change.logger=ERROR

and I see in the Kafka logs that Kafka is starting with the following configuration:

===> ENV Variables ...
ALLOW_UNSIGNED=false
COMPONENT=kafka
CONFLUENT_DEB_VERSION=1
CONFLUENT_PLATFORM_LABEL=
CONFLUENT_VERSION=5.4.1
...
KAFKA_LOG4J_LOGGERS=org.apache.zookeeper=ERROR, org.apache.kafka=ERROR, kafka=ERROR, kafka.cluster=ERROR, kafka.controller=ERROR, kafka.coordinator=ERROR, kafka.log=ERROR, kafka.server=ERROR, kafka.zookeeper=ERROR, state.change.logger=ERROR
KAFKA_LOG4J_ROOT_LOGLEVEL=ERROR
...

Still I see further down in the logs the INFO and TRACE log levels. For example:

[2020-03-26 16:22:12,838] INFO [Controller id=1001] Ready to serve as the new controller with epoch 1 (kafka.controller.KafkaController)
[2020-03-26 16:22:12,848] INFO [Controller id=1001] Partitions undergoing preferred replica election:  (kafka.controller.KafkaController)
[2020-03-26 16:22:12,849] INFO [Controller id=1001] Partitions that completed preferred replica election:  (kafka.controller.KafkaController)
[2020-03-26 16:22:12,855] INFO [Controller id=1001] Skipping preferred replica election for partitions due to topic deletion:  (kafka.controller.KafkaController)

How can I really deactivate the logs below a certain level? In the example above, I really want only ERROR logs.

  • The approach above is the way described in the Confluent documentation.
  • And the Apache Kafka source code lists all sorts of loggers that I could not influence using the KAFKA_LOG4J_LOGGERS Docker environment variable.
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168

1 Answers1

9

I went and troubleshot the Dockerfile's and inspected the Kafka container. The cause of this behaviour was the YAML multiline string folding.

Hence the provided environment variable (using a YAML multiline value) is at runtime:

KAFKA_LOG4J_LOGGERS=org.apache.zookeeper=ERROR, org.apache.kafka=ERROR, kafka=ERROR, kafka.cluster=ERROR, kafka.controller=ERROR, kafka.coordinator=ERROR, kafka.log=ERROR, kafka.server=ERROR, kafka.zookeeper=ERROR, state.change.logger=ERROR

instead of (no spaces in between):

KAFKA_LOG4J_LOGGERS=org.apache.zookeeper=ERROR,org.apache.kafka=ERROR, kafka=ERROR, kafka.cluster=ERROR,kafka.controller=ERROR, kafka.coordinator=ERROR,kafka.log=ERROR,kafka.server=ERROR,kafka.zookeeper=ERROR,state.change.logger=ERROR

And this was visible inside the container in the generated /etc/kafka/log4j.properties file:

log4j.rootLogger=ERROR, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n


log4j.logger.kafka.authorizer.logger=WARN
log4j.logger.kafka.cluster=ERROR
log4j.logger.kafka.producer.async.DefaultEventHandler=DEBUG
log4j.logger.kafka.zookeeper=ERROR
log4j.logger.org.apache.kafka=ERROR
log4j.logger.kafka.coordinator=ERROR
log4j.logger.org.apache.zookeeper=ERROR
log4j.logger.kafka.log.LogCleaner=INFO
log4j.logger.kafka.controller=ERROR
log4j.logger.kafka=INFO
log4j.logger.kafka.log=ERROR
log4j.logger.state.change.logger=ERROR
log4j.logger.kafka=ERROR
log4j.logger.kafka.server=ERROR
log4j.logger.kafka.controller=TRACE
log4j.logger.kafka.network.RequestChannel$=WARN
log4j.logger.kafka.request.logger=WARN
log4j.logger.state.change.logger=TRACE

If you really need to split the long line in a YAML multiline value, you would have to use this YAML syntax.

More hints from the code:

  • here is where the log4j.properties file is generated when a confluent container is run.
  • these are the default log levels that Kafka will start with.
  • these should be all the loggers supported by Kafka
paulochf
  • 690
  • 2
  • 11
  • 21
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
  • 3
    Note: Spaces matter. `log4j.logger. kafka.log=ERROR` might not get loaded – OneCricketeer Mar 28 '20 at 02:08
  • please note that in your one line example with no spaces, you do in fact still have spaces there. It should be: KAFKA_LOG4J_LOGGERS: org.apache.zookeeper=ERROR,org.apache.kafka=ERROR,kafka=ERROR,kafka.cluster=ERROR,kafka.controller=ERROR,kafka.coordinator=ERROR,kafka.log=ERROR,kafka.server=ERROR,kafka.zookeeper=ERROR,state.change.logger=ERROR – ChrisO Mar 09 '22 at 17:17