首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置log4j2配置?

如何设置log4j2配置?
EN

Stack Overflow用户
提问于 2021-08-25 18:43:35
回答 1查看 212关注 0票数 0

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

代码语言:javascript
复制
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

这是我的server.xml:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2021-08-25 21:16:00

您还需要将log4j添加到类路径中,有几种方法可以做到这一点(各有优缺点,但我建议使用#2,除非您有多个要使用log4j的应用程序,在这种情况下,3可能是更好的方法):

  1. 将其与您的应用程序打包(在war中)
  2. 通过webApplication
  3. Drop it in server.xml中的classloader属性将其添加到global shared library folder中:${shared.config.dir}/lib/global或通过JVM参数${server.config.dir}/lib/global
  4. Set将其添加到${shared.config.dir}/lib/global

我要提到的是,还有一个你可能会觉得有帮助的archived repo regarding using log4j with Open Liberty,但请记住,它是存档的,所以它很可能是不完整的,并且没有开发支持。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68928312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档