Open-liberty如何设置一个log4j配置?

xu3bshqb  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(81)

标题说明了一切。我如何在我的Open-liberty项目中设置log4j配置?我已经在resources文件夹中添加了log4j.xml文件,并在pom.xml中使用了以下依赖项:

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

字符串
这是我的server.xml:

<server description="Intake Server">
    <featureManager>
        <feature>servlet-4.0</feature>
        <feature>mpConfig-1.4</feature>
        <feature>cdi-2.0</feature>
    </featureManager>

    <variable name="default.http.port" defaultValue="9080"/>
    <variable name="default.https.port" defaultValue="9443"/>
    <variable name="app.context.root" defaultValue="message"/>

    <httpEndpoint httpPort="${default.http.port}" 
    httpsPort="${default.https.port}" id="defaultHttpEndpoint"  host="*" />

    <library id="log4jConfig">
          <folder dir="/var/log/intake" scanInterval="5s" />
    </library>

    <webApplication id="intake" location="intake.war" contextRoot="${app.context.root}">
        <classloader commonLibraryRef="log4jConfig"/>
    </webApplication>
</server>

muk1a3rh

muk1a3rh1#

您还需要将log4j添加到类路径中,有几种方法可以做到这一点(每种方法都有优点/缺点,但我建议使用#2,除非您有多个应用程序将使用log4j,在这种情况下,3可能是更好的方法):
1.将其与您的应用程序打包(在战争中)
1.通过webApplication下的classloader属性将其添加到server.xml中
1.放入global shared library folder${shared.config.dir}/lib/global${server.config.dir}/lib/global
1.通过JVM参数设置:-Dlog4j.configurationFile=file:/path/to/log4j2.xml
我会提到还有一个archived repo regarding using log4j with Open Liberty,你可能会发现它很有帮助,但请记住,它是存档的,所以它可能是不完整的,没有开发支持。

相关问题