Prior to log4j2
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.ELASTIC=com.my.ElasticSearchAppender
log4j.rootLogger=FILE,ELASTIC # Works
log4j2
appender.elastic.type=Elasticsearch
appender.elastic.name=elastic
appender.rolling.type=RollingFile
appender.rolling.name=rolling
rootLogger.appenderRef.root.ref=rolling,elastic # does not work
rootLogger.appenderRef.root.ref=rolling # works
rootLogger.appenderRef.root.ref=elastic # works
I get the below error.
Log4J Updater ERROR Unable to locate appender "rolling,elastic" for logger config "root"
Am I doing something wrong?
CodePudding user response:
Remark: your Log4j 1.x configuration is incorrect, since the configuration of the root logger must start with a level followed by zero or more appender names, e.g.:
log4j.rootLogger=INFO, FILE, ELASTIC
Since version 2.17.2 (cf. LOG4J2-3341) the same shorthand notation is available in the Log4j2 properties format:
rootLogger=INFO, file, elastic
The full notation can be easily converted from the simpler XML format:
<Root level="INFO">
<AppenderRef ref="file"/>
<AppenderRef ref="elastic"/>
</Root>
Each <AppenderRef>
element results in a appenderRef.<unique identifier>
property:
rootLogger.level = INFO
rootLogger.appenderRef.<0>.ref = file
rootLogger.appenderRef.<1>.ref = elastic
CodePudding user response:
I fixed the issue
rootLogger.appenderRefs=rolling,elastic
rootLogger.appenderRef.elastic.ref=elastic
rootLogger.appenderRef.rolling.ref=rolling