在外部log4j配置中包括类路径资源

时间:2019-05-15 08:06:36

标签: log4j2 xinclude

我使用外部log4j配置,并使用org.apache.logging.log4j.core.config.Configurator将其加载到servlet上下文侦听器中

我想引用一些在构建时生成的应用程序属性(例如应用程序版本)。 这是我想做的:

  

/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

应该是类路径资源, @version @ 由gradle过滤。

<?xml version="1.0" encoding="UTF-8"?>
<Properties>
    <Property name="app-version">@version@</Property>
</Properties>

但是这种方法行不通。我只能xinclude与顶级log4j.xml来自同一文件夹的资源

我该如何解决我的问题?

(我知道如何使用logback来执行此操作,但是我想升级到log4j2)

0 个答案:

没有答案
相关问题