Confluence Docker log4j 记录器级别配置

Gab*_*vay 5 logging log4j apache-kafka docker

我使用confluentinc/cp-kafkaDocker 映像在本地运行 Kafka,并设置以下日志记录容器环境变量:

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
Run Code Online (Sandbox Code Playgroud)

我在 Kafka 日志中看到 Kafka 以以下配置启动:

===> 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
...
Run Code Online (Sandbox Code Playgroud)

我仍然在日志中看到更下面的INFOTRACE日志级别。例如:

[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)
Run Code Online (Sandbox Code Playgroud)

如何真正停用低于特定级别的日志?在上面的例子中,我真的只想要ERROR日志。

Gab*_*vay 10

我去排除了故障Dockerfile并检查了 Kafka 容器。此行为的原因是 YAML 多行字符串折叠。

因此,提供的环境变量(使用 YAML 多行值)在运行时:

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
Run Code Online (Sandbox Code Playgroud)

而不是(中间没有空格):

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
Run Code Online (Sandbox Code Playgroud)

这在生成的文件的容器内可见/etc/kafka/log4j.properties

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
Run Code Online (Sandbox Code Playgroud)

如果您确实需要拆分 YAML 多行值中的长行,则必须使用此 YAML 语法

代码中的更多提示:

  • log4j.properties是运行汇合容器时生成文件的位置。
  • 这些是 Kafka 启动时的默认日志级别。
  • 这些应该是 Kafka 支持的所有记录器

  • 注意:空格很重要。`log4j.logger。kafka.log=ERROR` 可能无法加载 (3认同)