如何在 grails 中禁用 log4j 插件? [英] How do disable log4j plugin in grails?

查看:18
本文介绍了如何在 grails 中禁用 log4j 插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来 Grails 2.1 log4j 插件在 grails 应用程序初始化期间重置了 log4j 配置(请参阅下面的堆栈跟踪).

It appears the Grails 2.1 log4j plugin resets the log4j configuration during initialization of the grails application (see stack trace below).

    at org.apache.log4j.LogManager.resetConfiguration(LogManager.java:233)
    at org.apache.log4j.LogManager$resetConfiguration.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
    at org.codehaus.groovy.grails.plugins.log4j.Log4jConfig.initialize(Log4jConfig.groovy:66)
    at org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:48)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4389)
    at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:313)
    at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:145)

有什么办法可以禁用这个功能"或完全删除这个插件?

我的 JBoss 服务器已经通过 jboss-log4j.xml 进行了配置,我不希望 grails 对配置进行任何更改.我已经尝试删除 Config.groovy 的 log4j 部分,但这样做没有任何效果.

My JBoss server is already configured through jboss-log4j.xml and I do not want grails to make any changes to the configuration. I have already tried removing the log4j section of Config.groovy, but doing so had no effect.

正如凯利所建议的,我已经从我的战争文件中删除了所有与日志相关的 jar.Log4j 类由 JBoss 提供.

As Kelly suggested, I have already removed all logging-related jars from my war file. Log4j classes are provided by JBoss.

编辑我也尝试了https://stackoverflow.com/a/1190438/中描述的技巧539048 但这似乎没有任何区别.

EDIT I also tried the trick described in https://stackoverflow.com/a/1190438/539048 but that didn't seem to make any difference.

推荐答案

解决方案是从生成的 web.xml 文件中删除以下部分:

The solution was to remove the following section from the generated web.xml file:

<listener>
    <listener-class>org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener</tag0:listener-class>
</listener>

为此,我根据 this blog 但将监听器类名更改为 org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.

To do so, I edited the scripts/Events.groovy file according to this blog but changed the listener class name to org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.

eventWebXmlEnd = {String tmpfile ->

    def root = new XmlSlurper().parse(webXmlFile)

    def log4j = root.listener.findAll {node ->
        node.'listener-class'.text() == 'org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener'
    }
    log4j.replaceNode {}

    webXmlFile.text = new StreamingMarkupBuilder().bind {
        mkp.declareNamespace("": "http://java.sun.com/xml/ns/j2ee")
        mkp.yield(root)
    }
}

这篇关于如何在 grails 中禁用 log4j 插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆