无法更改 zookeeper 日志文件名

Cannot change zookeeper log filename

Zookeeper 正在创建名为 zookeeper-root-hostname.out 的日志,但这是我的 log4j.properties:

zookeeper.root.logger=INFO, CONSOLE
zookeeper.console.threshold=INFO

zookeeper.log.dir=.
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=INFO
zookeeper.log.maxfilesize=256MB
zookeeper.log.maxbackupindex=20

zookeeper.tracelog.dir=${zookeeper.log.dir}
zookeeper.tracelog.file=zookeeper_trace.log

log4j.rootLogger=${zookeeper.root.logger}

#
# console
# Add "console" to rootlogger above if you want to use this
#
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n

#
# Add ROLLINGFILE to rootLogger to get log file output
#
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
log4j.appender.ROLLINGFILE.MaxFileSize=${zookeeper.log.maxfilesize}
log4j.appender.ROLLINGFILE.MaxBackupIndex=${zookeeper.log.maxbackupindex}
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n

如果更改 属性 zookeeper.log.file=zookeeper.log 创建的同名文件,如何更改日志的文件名?

更新

我发现文件 zkServer.sh 设置了变量 ZOO_LOG_FILE 并覆盖了 log4j.properties:

中定义的值
ZOO_LOG_FILE=zookeeper-$USER-server-$HOSTNAME.log

我可以修改这个文件,但是可以手动更改吗?

搜索后我找到了这个 link 但我没有找到如何更改日志的变量,我注意到文件中 zkServer.sh 定义了文件的名称,所以我需要更改此变量:

_ZOO_DAEMON_OUT="$ZOO_LOG_DIR/zookeeper-$USER-server-$HOSTNAME.out"

我不知道是否可以更改该变量但知道它按预期工作。

在典型的 Java 应用程序方式中,Zookeeper 的日志记录情况非常复杂、自定义且记录不足。官方管理员手册 logging section is a tiny paragraph with about zero information, but suggests you can rely on your existing knowledge of the third party library log4j configured to proxy through the other third party library SLF4J. This actually wouldn't be too bad since that complicated arrangement is common as many popular open source projects ignore the built-in logging framework that ships will Java, but later you'll discover using the log4j.properties file in the conf directory actually doesn't work as expected 因为在提供的启动脚本 (zkServer.sh) 中使用了自定义属性,覆盖了许多内容。

为了设置文件名,请注意文件 conf/log4j.properties 包含以下被启动脚本 (zkServer.sh) 覆盖的变量赋值:

zookeeper.log.file=zookeeper.log

要么在外部设置环境变量,修改启动脚本,要么更新log4j.properties不使用该变量:

#log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
log4j.appender.ROLLINGFILE.File=/the/actual/path/goes/here.log

您可能还想像这样启用 ROLLINGFILE:

#log4j.rootLogger=${zookeeper.root.logger}
log4j.rootLogger=INFO,ROLLINGFILE