views:

49

answers:

2

I have a few log.debugs() that I don't want to process (since they are heavy) unless the app is currently in debug mode (not production).

Is there a way to check if the grails app is currently in debug mode/development mode?

A: 

in the config.groovy the environments are defined.

you can specify what you want the log configuration to be based on the environment the application in running in

environments {
    development {
        log4j = {
          // determine what appenders are logging in development...
        }
    }
    production {
        log4j = {
          // determine what appenders are logging in production...
        }
    }
}
Aaron Saunders
Thanks Aaron. I am aware of this. But I want to know the environment at run time so I can choose to perform certain calculations only if the env is development. Don's answer above looks like what I am looking for.
The Fat Oracle
A: 

You can test if the current environment is dev (for example) using the following:

import grails.util.Environment

if (Environment.currentEnvironment == Environment.DEVELOPMENT ) {
    // Do your dev logging here
}
Don
Don, this is what I was looking for. thanks!
The Fat Oracle