PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 25, 2022

[FIXED] How to configure writing to multiple Appenders in log4j2?

 October 25, 2022     elasticsearch, log4j     No comments   

Issue

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?


Solution

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


Answered By - Piotr P. Karwasz
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing