Grails采用Log4j记录日志信息,Log4j的配置信息写在config.groovy文件中。

// log4j configuration
log4j = {
    // Example of changing the log pattern for the default console appender:
    appenders {
         //console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
        //file name:'file', file:'/var/log/tomcat/revid.log'
        rollingFile name: "stacktrace", maxFileSize: 10240, file: "/var/log/tomcat/revid-stacktrace.log"
    }

    debug   'grails.app.controllers',
            'grails.app.controller',
            'grails.app.domain',
            'grails.app.services',
            'grails.app.filters',
            'com.mycompany',
            'org.hibernate.SQL'

    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',
            'net.sf.ehcache.hibernate'

    root {
        //error 'stdout', 'file'
        error 'stacktrace'
        additivity = true
    }
}
java中Log4j:
### set log levels ###
#log4j.rootLogger =debug,stdout,D,E
log4j.rootLogger =INFO,D,E


### console ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n

### file ###
log4j.appender.D = org.apache.log4j.RollingFileAppender 
log4j.appender.D.File = /var/log/tomcat/sm_info.log
#log4j.appender.D.Append = true
log4j.appender.D.Threshold = INFO
log4j.appender.D.layout = org.apache.log4j.PatternLayout 
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.D.MaxFileSize=10MB  
log4j.appender.D.MaxBackupIndex=20
log4j.appender.D.BufferedIO=false
log4j.appender.D.BufferSize=256 

### exceptions ###  
log4j.appender.E = org.apache.log4j.RollingFileAppender
log4j.appender.E.File = /var/log/tomcat/sm_error.log
#log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.E.MaxFileSize=10MB
log4j.appender.E.MaxBackupIndex=20
log4j.appender.E.BufferedIO=false
log4j.appender.E.BufferSize=256