I use external log4j configuration and load it in servlet context listener using org.apache.logging.log4j.core.config.Configurator
I would like to reference some application properties (like application version) that are generated on build time. Here is what I would like to do:
/external-folder/log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns:xi="http://www.w3.org/2001/XInclude"
monitorInterval="60">
<xi:include href="log4j2-properties.xml" />
<Appenders>
<Console name="stdout" target="SYSTEM_OUT">
<PatternLayout pattern="%d %5p %t [${app-version}] %m (%F:%L) %n" />
</Console>
</Appenders>
<!-- ... -->
</Configuration>
log4j2-properties.xml
is supposed to be a classpath resource, @version@ is filtered by gradle.
<?xml version="1.0" encoding="UTF-8"?>
<Properties>
<Property name="app-version">@version@</Property>
</Properties>
However this approach doesn't work. I can xinclude only resource from the same folder as top level log4j.xml
How can I solve my problem?
(I know how to do this using logback, but I would like to upgrade to log4j2)