How do disable log4j plugin in grails?

2020-02-26 13:50发布

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.

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-02-26 14:08

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)
    }
}
查看更多
萌系小妹纸
3楼-- · 2020-02-26 14:26

Modify your BuildConfig.groovy like this:

inherits("global") {
    excludes 'log4j', 'jcl-over-slf4j', 'slf4j-api', 'slf4j-log4j12'
}

This should remove all the logging libraries.

查看更多
登录 后发表回答