Search

Dark theme | Light theme

March 11, 2009

Default Log4j configuration expressed as closure for Grails 1.1

In Grails 1.1 the Log4j configuration has changed, because now a Log4j DSL is used. If we don't define a log4j closure in our Config.groovy we get a default configuration. The default configuration looks likes this if we had to define it as a closure:

log4j = {
    appenders {
        console name: 'stdout', layout: pattern(conversionPattern:'%d [%t] %-5p %c{2} %x - %m%n')
        file name: 'stackTraceLog', layout: pattern(conversionPattern:'%d [%t] %-5p %c{2} %x - %m%n'), file: 'stacktrace.log'
    }
    error 'org.springframework', 'org.hibernate'
    error stackTraceLog: 'StackTrace'
    root {
        error 'stdout'
    }
}

So we automatically get a console appender for root log level ERROR. And a file appender for the StackTrace logger with log level ERROR. Remember we don't have to define this closure, we can leave out the log4j closure to get these defaults.