如何使Log4J2在JBoss EAP 6.4中工作



我在网上看到了成功的实例,使Log4J2在JBoss EAP 6.x 中工作

我的本地战争文件有特定情况(JBoss EAP 6.4,JDK8(:

  1. war建立在Spring 3框架上,其中大多数日志记录都是由Apache Common Logging进行的
  2. 战争中的源代码记录由Slf4J进行
  3. 然而,WEB-INF/lib中的一些内部依赖关系仍然是由Log4J 1.2而不是slf4J产生的

所以我在项目中添加了以下依赖项,如下所示(只列出jar文件,而不是详细的pom-xml(:

### spring framework from jcl to slf4j
jcl-over-slf4j-1.7.25.jar
### slf4j to log4j 1.2 then to log4j2
slf4j-log4j12-1.7.25.jar
log4j-1.2-api-2.11.1.jar
### slf4j to log4j 2
slf4j-api-1.7.25.jar
slf4j-simple-1.7.25.jar
log4j-api-2.8.2.jar
log4j-core-2.8.2.jar
log4j-slf4j-impl-2.8.jar

我的计划是告诉EAP 6.4永远不要使用JBoss的任何日志模块,而只使用这场战争提供的任何东西,所以在jboss-deployment-structure.xml中我创建了以下元素

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
<dependencies>
<module name="oracle" />
</dependencies>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.jboss.logging" />
<module name="org.jboss.logging.jul-to-slf4j-stub" />
<module name="org.jboss.logmanager" />
<module name="org.jboss.logmanager.log4j" />
<module name="org.slf4j" />
<module name='org.slf4j.impl' />
<module name='org.slf4j.jcl-over-slf4j' />
</exclusions>
</deployment>
</jboss-deployment-structure>

当应用程序启动时,我可以看到以下信息显示在服务器日志中,提取于

Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/jcl-over-slf4j-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/slf4j-log4j12-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/slf4j-api-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/slf4j-simple-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-1.2-api-2.11.1.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-api-2.8.2.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-core-2.8.2.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-slf4j-impl-2.8.jar" to module deployment.MyApp.war:main

服务器日志中没有太多关于登录的进一步信息,没有错误。

然而,无论我如何配置日志附加程序(ROLConsole(,都不会生成log4J日志。我使用FileAppender,但没有生成日志文件。

我不认为这是由log4J配置问题引起的,因为相同的war文件具有相同的log4J2.xml,Tomcat 8中的日志输出很好

我如何才能做到这一点,至少应用程序输出日志记录成功。

依赖项中有多个SLF4J绑定:

  1. slf4j-simple-1.7.25.jar
  2. slf4j-log4j12-1.7.25.jar
  3. log4j-slf4j-impl-2.8.jar

操作1:删除slf4j-simple并选择slf4j-log4j12或log4j-slf4j-impl之一。

除此之外,log4j的两个API依赖项看起来可疑:

  1. log4j-1.2-api-2.11.1.jar
  2. log4j-api-2.8.2.jar

操作2:删除log4j-1.2-api-2.11.1.jar,因为您使用的是log4j的实现版本2.8.2。

最新更新