I wanted to add how I fixed this problem / customized my environment.
There are 2 logging mechanisms working here:
- bin/zkServer.sh redirects the zookeeper server's stdout and stderr to zookeeper.out
- log4j can append to logs to several places including:
- CONSOLE - which ends up in zookeeper server's stdout and stderr
- ROLLINGFILE - which is sent to zookeeper.log
bin/zkServer.sh uses :
- ZOO_LOG_DIR to set the path for both zookeeper.out and log4j.
- ZOO_LOG4J_PROP to set the log4j logging level and what log appenders are turned on
The "eventual" defaults in the setup conf/log4j.properties are set by a combination of zookeeper bash scripts:
- ZOO_LOG_DIR = . ( the working directory from which zookeeper is started )
- set inside of conf/log4j.properties as zookeeper.log.dir
- ZOO_LOG4J_PROP = INFO, CONSOLE
- set inside of conf/log4j.properties as zookeeper.root.logger
The effect of turning on the log appender CONSOLE is that logs now go to stdout. Because bin/zkServer.sh redirects stdout and stderr to zookeeper.out, log4j logs end up in zookeeper.out. The effect of turning off ROLLINGFILE is that no zookeeper.log file is created.
The zookeeper.out log is not rotated. The zookeeper.log log is set to be rotated and can be set to expire old logs.
I wanted logs to roll and be expired. The first thing I had to do was change conf/log4j.properties to cause the expiration/deletion of old logs. I did that by setting log4j.appender.ROLLINGFILE.MaxBackupIndex inside of conf/log4j.properties. The second thing I had to do was set the log directory, logging level and appenders.
I have a bash script that runs every minute. If it sees that zookeeper isn't running, it runs :
bin/zkServer.sh start
I changed it to specify environmental variables expected by bin/zkServer.sh.
sudo ZOO_LOG_DIR=/opt/zookeeper-3.4.6/logs ZOO_LOG4J_PROP='INFO,ROLLINGFILE' /opt/zookeeper-3.4.6/bin/zkServer.sh start
The effect of turning off the log appender CONSOLE is that log4j logs now no longer end up in zookeeper.out. The effect of turning on ROLLINGFILE is that zookeeper.log file is created, rotated, and expired.
BTW, conf/log4j.properties was apparently already in my classpath. I had to make no changes in that regard.
This chain contributed significantly to my understanding:
https://groups.google.com/forum/#!msg/nosql-databases/aebIvNnT0xY/doky1X9-WfwJ
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…