Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails WAR on Tomcat "Log4J" not working at all

I have log4j DSL correctly configured in my Config.groovy in a grails applicaiton. Running the application with grails run-app dumps perfect logging as I specified in the DSL. However after doing a grails war to generate a war file and deploying it to tomcat, logging just disappears. I can't see it working anywhere, except tomcat console showing millions of log statements at debug level and nothing going specific to my logging into log files.


log4j = {
        appenders {
                 appender new org.apache.log4j.DailyRollingFileAppender(name: "tomcatLog", datePattern: "'.'yyyy-MM-dd", file: "${logDirectory}/snm.log".toString(), layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
        }
        root {
            info 'stdout', 'tomcatLog'
            additivity = true
        }
        info    'grails.app',
                'grails.app.controller',
                'grails.app.bootstrap',
                'grails.app.service',
                'grails.app.task',
                'commons',
                'jsontwitter'
    }

Can you please explain the above DSL? It send commons.* and jsontwitter.* classes logs to designated log file but no controller, services log is saved in file.

Thanks, Alam Sher

like image 474
ask-dev Avatar asked Feb 14 '10 20:02

ask-dev


1 Answers

You need to find out, what logging directory tomcat uses. This is done by the following snippet of grails-app/conf/Config.groovy:

def catalinaBase = System.properties.getProperty('catalina.base')
if (!catalinaBase) catalinaBase = '.'   // just in case
def logDirectory = "${catalinaBase}/logs"

// default for all environments
log4j = { root ->
     appenders {
             rollingFile name:'stdout', file:"${logDirectory}/${appName}.log".toString(), maxFileSize:'100KB'
             rollingFile name:'stacktrace', file:"${logDirectory}/${appName}_stack.log".toString(), maxFileSize:'100KB'
    }

    error  'org.codehaus.groovy.grails.web.servlet',  //  controllers
           'org.codehaus.groovy.grails.web.pages', //  GSP
           'org.codehaus.groovy.grails.web.sitemesh', //  layouts
           'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
           'org.codehaus.groovy.grails.web.mapping', // URL mapping
           'org.codehaus.groovy.grails.commons', // core / classloading
           'org.codehaus.groovy.grails.plugins', // plugins
           'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
           'org.springframework',
           'org.hibernate'
    root.level = org.apache.log4j.Level.WARN
}

// special settings with production env
environments {
    development {
        log4j = { root ->
            appenders {
                       console name: 'stdout', layout: pattern(conversionPattern: "%d [%t] %-5p %c %x - %m%n")
            }
            warn       'org.codehaus.groovy.grails.web.servlet',  //  controllers
                       'org.codehaus.groovy.grails.web.pages', //  GSP
                       'org.codehaus.groovy.grails.web.sitemesh', //  layouts
                       'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
                       'org.codehaus.groovy.grails.web.mapping', // URL mapping
                       'org.codehaus.groovy.grails.commons', // core / classloading
                       'org.codehaus.groovy.grails.plugins', // plugins
                       'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
                       'org.springframework',
                       'org.hibernate'
            debug  'com.netjay'
            root.level = org.apache.log4j.Level.INFO
        }
    }
}
like image 80
Stefan Armbruster Avatar answered Oct 05 '22 22:10

Stefan Armbruster