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

查看:76
本文介绍了为什么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?

***UPDATE,我在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.

这里有 2 种日志机制:

There are 2 logging mechanisms working here:

  • 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 日志记录级别以及打开哪些日志附加程序

    setup 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

      打开日志附加器控制台的效果是日志现在转到标准输出.因为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
      

      关闭 log appender 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天全站免登陆