views:

706

answers:

2

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

A: 

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
        }
    }
}
Stefan
This does the logging for me. But as I have updated the question, can you please take a look at the DSL I specified for my logging and tell me what might be wrong with this, as no logs from services, domains, controllers are going to designated appenders except for the socurce packages e.g. commons and jsontwitter.Also in catalina.out everything is getting appended but with huge DEBUG level logging as well :(So this is kind of very confusing for me.
Alam Sher
I think the package definitions in your DSL is wrong. You need to remove the prefix "grails.app". So if your domain class is located in package com.mycompany.abc.MyCoolDomainClass, you must use com.mycompany.abc in the DSL. If you don't yet use packages in your domain classes, controllerer, etc. it is recommended to always use packages and never put anything in the root package.
Stefan
A: 

There is also a bug on jira : http://jira.codehaus.org/browse/GRAILS-5666 : Run-war has some classpath conflicts.

Marc Palmer says :logging is killed in apps using plugins that define deps that inherit "global"

Dreur