log4j:用于设置日志级别的单个追加程序块对我不起作用

时间:2018-10-17 13:12:41

标签: log4j apache-zookeeper appender

在尝试将Zookeeper日志级别设置为通过环境变量设置的值时,该错误包含以下消息:

2018-10-17T00:45:32.658628+00:00 cherry-zk-node zookeeper: log4j:ERROR Could not find value for key log4j.appender.TRACE
2018-10-17T00:45:32.658902+00:00 cherry-zk-node zookeeper: log4j:ERROR Could not instantiate appender named "TRACE".
2018-10-17T12:45:32.692874+00:00 cherry-zk-node zookeeper: log4j:ERROR Could not find value for key log4j.appender.TRACEFILE
2018-10-17T00:45:32.693154+00:00 cherry-zk-node zookeeper: log4j:ERROR Could not instantiate appender named "TRACEFILE".

下面是log4j.properties文件

zookeeper.root.logger=$ENV_VARIABLE
zookeeper.console.threshold=$ENV_VARIABLE
zookeeper.log.file=zk.log
zookeeper.log.threshold=$ENV_VARIABLE
zookeeper.log.dir=.

log4j.rootLogger=${zookeeper.root.logger}

# CONSOLE  
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout

# Set Appenders for ALL log levels from ENV variable
log4j.appender.WARN.Threshold=${zookeeper.console.threshold}
log4j.appender.INFO.Threshold=${zookeeper.console.threshold}
log4j.appender.ERROR.Threshold=${zookeeper.console.threshold}
log4j.appender.TRACE.Threshold=${zookeeper.console.threshold}

# Max log file size of 25MB
log4j.appender.ROLLINGFILE.MaxFileSize=25MB

1 个答案:

答案 0 :(得分:0)

根据您的错误消息,您应该添加名为“ log4j.appender.TRACE”和“ log4j.appender.TRACEFILE”的附加程序。也许是重复,您可以先从ENV_VARIABLE中删除“ TRACEFILE”。

添加

log4j.appender.TRACE=org.apache.log4j.FileAppender
log4j.appender.TRACE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
log4j.appender.TRACE.layout=org.apache.log4j.PatternLayout
log4j.appender.TRACE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n

log4j.properties

的末尾