大网数据广告活动
服务器运维问答

Kafka stores log4j logs in directory literally called ${kafka.logs.dir}

· 52CE 我爱测

I installed a preview version of Kafka 3.0 with log4j2 support ( http://home.apache.org/~dongjin/post/apache-kafka-log4j2-support/ ) on a RHEL 8 server. Kafka and Zookeeper are running successfully as systemd user services. I set…

问题原文

原帖链接 · Cabbage Parachute · CC BY-SA 4.0

I installed a preview version of Kafka 3.0 with log4j2 support (http://home.apache.org/~dongjin/post/apache-kafka-log4j2-support/) on a RHEL 8 server. Kafka and Zookeeper are running successfully as systemd user services. I set the environment variable KAFKA_LOG4J_OPTS="-Dlog4j.configurationFile=file:/home/username/kafka/bin/../config/log4j2.properties" in the systemd unit file so that log4j 2.17 ist used.

However, there is one strange thing: all log4j logs are stored in a directory literally called ${kafka.logs.dir} in the home directory. The garbage collector successfully stores logs in the correct log location ~/kafka/logs. So the directory ~/kafka/logs contains files like kafkaServer-gc.log.0.current, while the hilariously strange directory ~/${kafka.logs.dir} contains server.log, controller.log, etc.

When looking at the processes for kafka and zookeeper, I can see that they both have the argument -Dkafka.logs.dir=/home/username/kafka/bin/../logs. Shouldn't this define the environment variable kafka.logs.dir, which is used in the file config/log4j2.properties? How come that Zookeeper and Kafka apparently don't have access to this $kafka.logs.dir environment variable?

已采纳解答

原帖链接 · Lee Dongjin · CC BY-SA 4.0

Just add sys: prefix to the kafka.logs.dir system variable in the log4j2.properties file. That is:

  • AS-IS: ${kafka.logs.dir}
  • TO-BE: ${sys:kafka.logs.dir}

DISCLAIMER: As you can see in my name, I wrote this code (log4j2 migration of Apache Kafka) and am maintaining the preview build. The fix will be released soon. Sorry for being late.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-12-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。