Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does zookeeper not use my log4j.properties file log directory

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...

like image 978
smuggledPancakes Avatar asked Oct 28 '14 15:10

smuggledPancakes


People also ask

Is ZooKeeper affected by log4j?

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).

Where do I put log4j properties file?

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.

Where are ZooKeeper logs stored?

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.


2 Answers

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

like image 91
Jeff Maass Avatar answered Sep 22 '22 10:09

Jeff Maass


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" 
like image 26
jorfus Avatar answered Sep 22 '22 10:09

jorfus