grailslog4jperf4j

How to resolve class references in an external config file for grails war deployment?


I am using Grails 1.3.7. I build a war file & deploy it in tomcat. I have an external groovy configuration file that I use to set up logging. I added some perf4j logging appenders to the declaration, but now the configuration file fails to compile because it cannot resolve the fully-qualified class names.

The code looks like this:

log4j = {
    ...
    // file appender that writes out the URLs of the Google Chart API graphs generated by the performanceGraphAppender
    def performanceGraphFileAppender = new org.apache.log4j.FileAppender(
        fileName: "log/perfGraphs.log",
        layout: pattern(conversionPattern: '%m%n')
    )
    appender name: 'performanceGraphFileAppender', performanceGraphFileAppender

    // this appender creates the Google Chart API graphs
    def performanceGraphAppender = new org.perf4j.log4j.GraphingStatisticsAppender(
        graphType: 'Mean',      // possible options: Mean, Min, Max, StdDev, Count or TPS
        tagNamesToGraph: 'tag1,tag2,tag3',
        dataPointsPerGraph: 5
    )
    performanceGraphAppender.addAppender(performanceGraphFileAppender)
    appender name: 'performanceGraph', performanceGraphAppender

    ...
}

and the error message that's written out into the log is this:

script1317679813518843914255.groovy: 38: unable to resolve class org.perf4j.log4j.GraphingStatisticsAppender 
@ line 38, column 34.
    def performanceGraphAppender = new org.perf4j.log4j.GraphingStatisticsAppender(

The war file I am building contains all the required JARs. Any thoughts on how to get it to resolve the references?

Thanks,

Gene


Solution

  • There is a possibility that after deployment, it starts using log4j from tomcat. Take a look at lib folder, maybe it's contains log4j jars. If that's true - the it uses different classloader, that can't see your perf4j classes.

    You can try to put your perf4j jars into tomcat's lib, probably it can fix this issue