I am trying to use the RewriteAppender to make mods to the LogEvent and then pass it along to several other appenders. (My environment requires all configurations to use properties files.)
In looking at the code in PropertiesConfigurationBuilder methods processRemainingProperties() and createComponent, it is not clear how to configure this if it is even possible at all.
The documentation (https://logging.apache.org/log4j/2.x/manual/configuration.html#configuration-with-properties) has an example that includes:
logger.app.appenderRef.$1.ref = stdout
logger.app.appenderRef.$2.ref = file
My latest attempt to configure this array was this: (note the plural "appenderRefs" since that is the plugin builders parameter name)
# added for error "No type attribute for component appenderRefs"
appender.rewrite.appenderRefs.type = AppenderRef
appender.rewrite.appenderRefs.stdout.type = AppenderRef
appender.rewrite.appenderRefs.stdout.ref = stdout
appender.rewrite.appenderRefs.file.type = AppenderRef
appender.rewrite.appenderRefs.file.ref = file
I was expecting the appenderRefs RewriteAppender property to be set to an array with two elements but I get the following ConfigurationException:
Arguments given for element RewriteAppender are invalid: field 'appenderRefs' has invalid value '[Lorg.apache.logging.log4j.core.config.AppenderRef;@740fb309'
As you already noticed, the general rule used to transform a set of properties into an XML tree transforms:
into the subtree:
So assuming
appender.rewriteis the prefix of theRewriteappender, you can use:Why does the example from the documentation work?
Beyond the general rule (expressed in the
processRemainingPropertiesmethod), some sub-trees have special rules. For example the properties that start withlogger.are parsed bycreateLogger, which accepts the syntax you found in the doc:but does not accept:
Remark: the
3.xversion of Log4j will feature a newlog4j-config-propertieswith coherent mapping rules provided byjackson-dataformat-properties. Under these new rules you'll be able to write: