标题说明了一切。如何在我的Open-liberty项目中设置log4j2配置?我已经在资源文件夹中添加了我的log4j2.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>发布于 2021-08-25 21:16:00
您还需要将log4j添加到类路径中,有几种方法可以做到这一点(各有优缺点,但我建议使用#2,除非您有多个要使用log4j的应用程序,在这种情况下,3可能是更好的方法):
${shared.config.dir}/lib/global或通过JVM参数${server.config.dir}/lib/global${shared.config.dir}/lib/global中我要提到的是,还有一个你可能会觉得有帮助的archived repo regarding using log4j with Open Liberty,但请记住,它是存档的,所以它很可能是不完整的,并且没有开发支持。
https://stackoverflow.com/questions/68928312
复制相似问题