Search

Dark theme | Light theme

March 11, 2009

Change Log4j log level for different environments in Grails 1.1

This blog post is an update for Grails 1.1 for a previous post. In Grails 1.1 the Log4j configuration is done with a Log4j DSL. We must define a closure in Config.groovy to define the Log4j configuration. We cannot override certain properties anymore for different environments, but we must define a new log4j closure for each environment we want a different Log4j configuration for.

So if we want to set a different loglevel for the root logger for each environment we can do so with this code:

environments {
    development {
        log4j = {
            root { debug() }
        }
    }
    test {
        log4j = {
            root { warn() }
        }
    }
    production {
        log4j = {
            root { error() }
        }
    }
}