在JBoss 7.1中使用log4j[英] Using log4j with JBoss 7.1

本文是小编为大家收集整理的关于在JBoss 7.1中使用log4j的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何将log4j与jboss 7.1?

使用

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

如果我将Dependencies: org.apache.commons.logging添加到我的 subtest.mf 文件,我会得到相同的结果.

这导致了我的 log4j.properties 文件(我创建的Unter Web-Inf/class)的问题.

推荐答案

很快就会有一种方法将为您工作从部署中排除log4j依赖项.您还必须手动调用propertyconfigurator.configure()加载属性文件.

以下文件( a>)需要包含以下内容:

<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版本应按照您的期望工作.

本文地址:https://www.itbaoku.cn/post/1574741.html

问题描述

How can I use log4j with JBoss 7.1?

I have a log4j-1.2.16.jar in my WebContent/WEB-INF/lib folder. When I output the result of Logger.getRootLogger().getClass().toString() I get class org.jboss.logmanager.log4j.BridgeLogger which is wrong.

If I add Dependencies: org.apache.commons.logging to my MANIFEST.MF file I get the same result.

This results into the problem that my log4j.properties file (which I created unter WEB-INF/classes) is ignored.

推荐答案

There will soon be a way that will just work for you, but currently you have to exclude the log4j dependency from your deployment. You will also have to manually invoke the PropertyConfigurator.configure() to load the properties file.

The following file (jboss-deployment-structure.xml) needs to contain the following:

<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>

Then adding including your own version of log4j in the WEB-INF/lib directory should work as you expect it to.