如何log4j.properties在confluent zookeeper中覆盖www.example.com

zphenhs4  于 2022-11-06  发布在  Zookeeper
关注(0)|答案(2)|浏览(259)

我们遇到了无法覆盖log4j.properties的问题。
这是我们的代码Dockerfile

FROM confluentinc/cp-zookeeper:6.2.0

# RUN chmod 777 /etc/kafka/connect-log4j.properties

USER root
COPY ./log4j.properties /etc/kafka/log4j.properties

log4j.properties

log4j.rootLogger=INFO, ROLLINGFILE

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n

log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=DEBUG
log4j.appender.ROLLINGFILE.File=/var/log/zookeeper.log

注意:-我们正在使用这个融合的Zookeeper'confluentinc/cp-Zookeeper:6.2.0'

s2j5cfk0

s2j5cfk01#

或者,也可以复制模板文件

FROM confluentinc/cp-zookeeper:6.2.0
COPY --chown=appuser:appuser ./log4j.properties.template /etc/confluent/docker/log4j.properties.template

其中

log4j.rootLogger={{ env["ZOOKEEPER_LOG4J_ROOT_LOGLEVEL"] | default('INFO') }}, rollingfile

log4j.appender.rollingfile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingfile.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingfile.File=/var/log/kafka/zookeeper.log
log4j.appender.rollingfile.layout.ConversionPattern=[%d] %p %m (%c)%n
log4j.appender.rollingFile.MaxFileSize=10MB
log4j.appender.rollingfile.MaxBackupIndex=1
log4j.appender.rollingFile.append=true

{% if env['ZOOKEEPER_LOG4J_LOGGERS'] %}
{% set loggers = parse_log4j_loggers(env['ZOOKEEPER_LOG4J_LOGGERS']) %}
{% for logger,loglevel in loggers.items() %}
log4j.logger.{{logger}}={{loglevel}}, rollingfile
{% endfor %}
{% endif %}
k5ifujac

k5ifujac2#

你不应该在log4j文件中复制。这会在运行时被这里定义的Jinja 2模板覆盖-https://github.com/confluentinc/kafka-images/blob/master/zookeeper/include/etc/confluent/docker/log4j.properties.template
要设置自定义记录器,只需将ZOOKEEPER_LOG4J_LOGGERS的环境变量添加到现有映像中,而不必创建自己的环境变量
您还应该使用Docker日志记录桥,而不是强制进程写入容器中的文件

相关问题