zookeeper为什么不使用我的log4j.properties文件日志目录 [英] Why does zookeeper not use my log4j.properties file log directory

查看:32
本文介绍了zookeeper为什么不使用我的log4j.properties文件日志目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 zookeeper/conf/log4j.properties 文件中,我将 zookeeper.log.dir 设置为 $HOME/zklogs

In my zookeeper/conf/log4j.properties file I set the zookeeper.log.dir to $HOME/zklogs

当我使用 zkServer.sh 时,它不使用该目录.相反,它使用 ${ZOO_LOG_DIR} ,当我回显它时,它会出现在."

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

我不明白如何解决这个问题,我在任何地方都没有看到 ${ZOO_LOG_DIR} 设置.我不确定它是如何设置为."一点也不.我也不知道如何在没有 zkServer.sh 的情况下启动 zookeeper.我对 linux 也很陌生,在这个问题上有点迷茫......

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

有人知道我该如何解决这个问题,以便它使用我在 conf 目录中的 log4j.properties 文件中设置的目录吗?

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?

***更新,我在我的 zookeeper 安装的 bin 目录中找到了 zkEnv.sh.有代码:

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

我不确定第一行发生了什么,但一定是这里出了点问题.我希望它从我的 log4j.properties 文件中查看 zookeeper.log.dir.谁能告诉我这是否应该是真的?我不想在这里硬连线路径...

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

推荐答案

我想补充一下我如何解决这个问题/自定义我的环境.

I wanted to add how I fixed this problem / customized my environment.

这里有两种日志机制:

  • bin/zkServer.sh 将zookeeper服务器的stdout和stderr重定向到zookeeper.out
  • log4j 可以将日志附加到多个位置,包括:
    • CONSOLE - 最终出现在 zookeeper 服务器的 stdout 和 stderr 中
    • ROLLINGFILE - 发送到 zookeeper.log

    bin/zkServer.sh 使用:

    bin/zkServer.sh uses :

    • ZOO_LOG_DIR 为 zookeeper.out 和 log4j 设置路径.
    • ZOO_LOG4J_PROP 设置 log4j 日志记录级别以及打开哪些日志附加程序

    设置 conf/log4j.properties 中的最终"默认值由 zookeeper bash 脚本组合设置:

    The "eventual" defaults in the setup conf/log4j.properties are set by a combination of zookeeper bash scripts:

    • ZOO_LOG_DIR = .(启动 zookeeper 的工作目录)
      • 在 conf/log4j.properties 中设置为 zookeeper.log.dir
      • 在 conf/log4j.properties 中设置为 zookeeper.root.logger

      打开日志附加器 CONSOLE 的效果是日志现在转到标准输出.因为 bin/zkServer.sh 将 stdout 和 stderr 重定向到 zookeeper.out,所以 log4j 日志最终在 zookeeper.out 中.关闭ROLLINGFILE的效果是没有创建zookeeper.log文件.

      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.

      zookeeper.out 日志没有轮换.zookeeper.log 日志设置为轮换,可以设置为过期旧日志.

      The zookeeper.out log is not rotated. The zookeeper.log log is set to be rotated and can be set to expire old logs.

      我希望日志滚动并过期.我要做的第一件事是更改 conf/log4j.properties 以导致旧日志过期/删除.我通过在 conf/log4j.properties 中设置 log4j.appender.ROLLINGFILE.MaxBackupIndex 来做到这一点.我要做的第二件事是设置日志目录、日志级别和附加程序.

      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.

      我有一个每分钟运行一次的 bash 脚本.如果它看到 zookeeper 没有运行,它就会运行:

      I have a bash script that runs every minute. If it sees that zookeeper isn't running, it runs :

      bin/zkServer.sh start
      

      我将其更改为指定 bin/zkServer.sh 预期的环境变量.

      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
      

      关闭日志附加器 CONSOLE 的效果是 log4j 日志现在不再以 zookeeper.out 结尾.开启ROLLINGFILE的效果是zookeeper.log文件被创建、轮换、过期.

      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.

      顺便说一句,conf/log4j.properties 显然已经在我的类路径中.在这方面我不必做任何改变.

      BTW, conf/log4j.properties was apparently already in my classpath. I had to make no changes in that regard.

      这条链对我的理解做出了重大贡献:https://groups.google.com/forum/#!msg/nosql-数据库/aebIvNnT0xY/doky1X9-WfwJ

      This chain contributed significantly to my understanding: https://groups.google.com/forum/#!msg/nosql-databases/aebIvNnT0xY/doky1X9-WfwJ

      这篇关于zookeeper为什么不使用我的log4j.properties文件日志目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆