1

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.

Community
  • 1
  • 1
GreenGiant
  • 4,930
  • 1
  • 46
  • 76

3 Answers3

3

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)
    }
}
GreenGiant
  • 4,930
  • 1
  • 46
  • 76
  • 1
    If this adds prefix tag0 to all of the tag names in your web.xml and you do not want to have it there, use namespace http://java.sun.com/xml/ns/javaee instead of http://java.sun.com/xml/ns/j2ee. – Palo Nov 07 '12 at 12:06
1

Modify your BuildConfig.groovy like this:

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

This should remove all the logging libraries.

Kelly
  • 3,709
  • 4
  • 20
  • 31
  • There are no logging jars in my war file (I have already done something equivalent to what you suggest). I made this more explicit in the question. Notice also from the stack trace that it is a grails plugin (`org.codehaus.groovy.grails.plugins.log4j.Log4jConfig`). – GreenGiant Jul 31 '12 at 15:05
  • I tried the above suggestion on [this][1] grails application, so that I could expect to exclude the log4j dependencies of grails. However, after applying the suggestion, the jar files expected to be removed are still there in the generated war file. These jar files are: ./lib/grails-plugin-log4j-2.4.4.jar and ./lib/log4j-1.2.17.jar [1]: https://github.com/WebDataConsulting/billing – Vikas Dec 21 '21 at 15:20
1

I tried the above suggestion on this grails application, so that I could expect to exclude the log4j dependencies of grails. However, after applying the suggestion, the jar files expected to be removed are still there in the generated war file. These jar files are: ./lib/grails-plugin-log4j-2.4.4.jar and ./lib/log4j-1.2.17.jar

Vikas
  • 4,184
  • 2
  • 12
  • 9