Loading...

March 9, 2009

Change Log4j log level for different environments in Grails

Grails uses Log4j for logging and we can find the Log4j configuration in the Config.groovy file. We can change the Log4j configuration for each environment. To achieve this we must override the default Log4j configuration for an environment. After the Log4j configuration block in the Config.groovy file we add for example the following code to change the rootLogger for the development, test and production environment:

environments {
    development {
        log4j {
           rootLogger="debug,stdout"
        }
    }
    test {
       log4j {
           rootLogger="warn,stdout"
       }
    }
    production {
       log4j {
           rootLogger="error,stdout"
       }
    }
}

This way we can override any setting of the Log4j configuration file for any environment.