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

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

问题描述

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

<$ p $在org.apache.log4j.LogManager.resetConfiguration(LogManager.java:233)
at org.apache.log4j.LogManager $ resetConfiguration.call(Unknown Source)
at at org.apache.log4j.LogManager.resetConfiguration 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)
org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910 )在org.apache.catalina.core.S上
tandardContext.start(StandardContext.java:4389)
位于org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:313)
位于org.jboss.web.tomcat。 service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:145)

有没有办法禁用这个功能或者完全删除这个插件?

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



由于Kelly建议,我已经从我的war文件中删除了所有与日志相关的jar。 Log4j类由JBoss提供。



编辑我也尝试了 https://stackoverflow.com/a/1190438/539048 ,但似乎没有任何区别。

解决方案

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

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

为此,我编辑了 scripts / Events.groovy 文件根据此博客,但将侦听器类名称更改为 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)
}
}


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)

Is there any way to disable this "feature" or to remove this plugin altogether?

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.

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

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

解决方案

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>

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天全站免登陆