2

I would like to write a standard configuration file for log4j2 and extend it for special cases(test environments,modules, etc).Which would allow me to make a change in the main configuration file without repeating it in a alternative configuration file.

So far I have tried xinclude, which works great for separating the main elements of the xml configuration but I can not add anything to those elements after the include. I have tried using the xPointer but only the element scheme is supported and I am not sure if it is possible to include all the children of an element with the element scheme.

Example

Appenders file:

<Appenders>
    <Appender 1 ...>
    <Appender 2 ...>
    <Appender 3...>
<Appenders>

This works but i would like to add more appenders after the include

    <Configuration xmlns:xi="http://www.w3.org/2001/XInclude"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               status="warn" name="XMLConfigTest" packages="com.patternconverters">
    <xi:include href="default-appenders.xml"/>
    <Loggers>
        <root level="ERROR">
            <appender-ref ref="LOG_ASYNC"/>
        </root>
    </Loggers>
</Configuration>

Since log4J2 only allows one "Appenders" element to be defined I need a way to do the include that only returns the child elements.

I have tried

<xi:include href="appenders.xml" xpointer="xpointer(//Appenders/*)"/>

and other combinations of using xpointer, but get the error that the xpointer scheme is unsupported.

Is there a way to get this functionality with the element scheme? So far i have only been able to include a specific element using element(/1/n) where n is the position of the element.

Is there another way to get this functionality in xml supported by log4j2(uses the Apache Xerces parser i believe)?

UPDATE:

After much research i was unable to find a native solution of xerces/log4j2. The two available alternatives i've found are to use a third party preprocessor that supports XPointer scheme includes or to extend/rewrite log4j2 XMLConfiguration to support multiple config files. Neither are a viable option for me at this time.

Community
  • 1
  • 1
alan7678
  • 2,223
  • 17
  • 29
  • Actually there seems to be no way to achieve such an inclusion. There's an open ticket ([LOG4J2-494](https://issues.apache.org/jira/browse/LOG4J2-494) allowing to use multiple config files and merging them together (kind of replacement for xinclude need). But there's nothing you could use yet. – philnate Jan 25 '16 at 12:25
  • So what's possible as of today is to have multiple files (one for each part you want to include) for inclusion, see http://stackoverflow.com/a/30478905/1377224 . – philnate Jan 25 '16 at 12:27

0 Answers0