Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...