【问题标题】:Using log4j with JBoss 7.1在 JBoss 7.1 中使用 log4j
【发布时间】:2012-03-23 23:53:42
【问题描述】:

如何在 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 文件(我在 WEB-INF/classes 下创建)被忽略的问题。

【问题讨论】:

    标签: log4j jboss7.x


    【解决方案1】:

    很快就会有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 应该可以正常工作。

    【讨论】:

    • 非常感谢您。我真的很沮丧。
    • 什么不起作用?什么版本的 JBoss AS 或 WildFly?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    相关资源
    最近更新 更多