在JBoss 7.1中使用log4j

问题描述:

如何在JBoss 7.1中使用log4j?在JBoss 7.1中使用log4j

我在我的WebContent/WEB-INF/lib文件夹中有一个log4j-1.2.16.jar。当我输出Logger.getRootLogger().getClass().toString()的结果时,我得到了class org.jboss.logmanager.log4j.BridgeLogger这是错误的。

如果我将Dependencies: org.apache.commons.logging添加到我的MANIFEST.MF文件我得到的结果相同。

这会导致问题,我的log4j.properties文件(我创建的unter WEB-INF/classes)被忽略。

很快就会有一种方式,will just work for you,但目前您必须从部署中排除log4j依赖项。您还必须手动调用PropertyConfigurator.configure()来加载属性文件。

以下文件(jboss-deployment-structure.xml)需要包含以下内容:

<jboss-deployment-structure> 
    <deployment> 
     <!-- Exclusions allow you to prevent the server from automatically adding some dependencies --> 
     <exclusions> 
      <module name="org.apache.log4j" /> 
     </exclusions> 
    </deployment> 
</jboss-deployment-structure> 

然后加入包括在WEB-INF/lib目录中的log4j的自己的版本,你期望它应该工作。

+2

非常感谢你。我真的很沮丧。 – T3rm1 2012-03-07 07:53:04

+0

不适用于我:( – 2013-12-22 06:56:29

+0

什么是行不通的?什么版本的JBoss AS或WildFly? – 2013-12-23 23:25:17