Grails: Only log error message in production

@drse / updated June 27, 2015

Share:  

Add to grails Config.groovy:

environments {
  development {
    grails.logging.jul.usebridge = true
  }
  production {
    grails.logging.jul.usebridge = false
    // Overwrite root logger to only log error messages:
    log4j = {
      root { error() }
    }
  }
}

A full log4j config may look like:

environments {
  development {
    grails.logging.jul.usebridge = true
  }
  production {
    grails.logging.jul.usebridge = false
    log4j = {
      root { error() }
    }
  }
}

log4j.main = {
  debug  'my.app.package'
  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
         'org.springframework',
         'org.hibernate',
         'net.sf.ehcache.hibernate'
  info   'org.springframework.security'
  debug  'grails.app.controllers', // messages from app's grails artefacts
         'grails.app.conf',
         'grails.app.domain',
         'grails.app.services',
         'grails.app.jobs'
}