In my zookeeper/conf/log4j.properties file I set the zookeeper.log.dir to $HOME/zklogs
When I use zkServer.sh it does not use that directory. Instead it uses the ${ZOO_LOG_DIR} which when I echo it, comes out to "."
I don't understand how fix this issue, I don't see the ${ZOO_LOG_DIR} set anywhere. I am not sure how it gets set to "." at all. I also don't know how to launch zookeeper without zkServer.sh. I am noobish at linux too and a little lost on this issue...
Does anybody know how I can fix this issue so that it uses the directory set in my log4j.properties file in the conf directory?
***UPDATE, I found in zkEnv.sh in the bin directory of my zookeeper install. There is code:
if["x${ZOO_LOG_DIR}" = "x" ] then ZOO_LOG_DIR="." fi
I am not sure what is going on in that first line, but it has to be here that something is going wrong. I expect it to look at zookeeper.log.dir from my log4j.properties file. Can anybody tell me if that should be true? I don't want to just hardwire the path here...
Zookeeper is apparently trying to access directly Log4j 1.2 internal classes, which do not exist any more in log4j-1.2-api (cf. source code).
During Content Engine installation, two log4j sample files are placed on the system in the ContentEngine\config\samples\ folder: log4j. properties. client: A Java format file that contains client configuration settings.
Apache Zookeeper log files are kept in /opt/apigee/var/log/zookeeper. Normally, log file maintenance should not be required, but if you find that there are an excessive number of ZooKeeper logs or that the logs are very large you can modify ZooKeeper's log4j properties to set the maximum file size and file count.
I wanted to add how I fixed this problem / customized my environment.
There are 2 logging mechanisms working here:
bin/zkServer.sh uses :
The "eventual" defaults in the setup conf/log4j.properties are set by a combination of zookeeper bash scripts:
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
zkServer.sh
gets it's environment variables from zkEnv.sh
The env file sets a classpath which includes the log4j file if it's at the expected location.
ZOOXFGDIR=ZOOBINDIR/../conf
I dropped some echos into zkServer.sh to trace what's going on. I found that classpath was being set properly, but logdir and log4j_prop were not being set. So I added them to zkEnv.sh
. Logs appear to be showing up in the expected location now.
ZOO_LOG_DIR="/var/log/zookeeper" ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With