如何在项目中包含多个log4j2.xml文件?

我的项目由多个模块组成。 每个模块都可以独立运行,并具有单独的log4j2.xml

说项目X由三个模块组成:

  1. 模块A有log4j2.xml(包含Loggers和Appenders)
  2. 模块B有log4j2.xml
  3. 模块C有log4j2.xml

在集成模块时,我必须手动将LoggersAppender从每个模块的log4j2.xml复制粘贴到项目特定的log4j2.xml文件中。

为了避免复制粘贴,我一直在寻找包含多个文件的XInclude ,但它只支持Appenders和Logger在不同的文件中。 http://logging.apache.org/log4j/2.x/manual/configuration.html#XInclude

如何XInclude多个log4j2.xml文件?

任何帮助是极大的赞赏。

在Log4j2 v2.6版本中,添加了复合配置function。 使用此function,允许多个log4j2配置文件。

参考
https://issues.apache.org/jira/browse/LOG4J2-494
https://github.com/Kamal15/Log4j2Examples/blob/master/src/main/java/in/co/nmsworks/log4j2/examples/CompositeConfigurationExample.java