Skip to content

Instantly share code, notes, and snippets.

@marhan
Forked from steinwaywhw/Config.groovy
Last active August 29, 2015 14:24
Show Gist options
  • Save marhan/03839fca410c09eb211b to your computer and use it in GitHub Desktop.
Save marhan/03839fca410c09eb211b to your computer and use it in GitHub Desktop.

Configuring log4j in Grails

Special thanks to this blog. This is the best blog on log4j configuration for Grails I've ever read.

Tips

  • If you wanna reference your own configuration in log4j config section, use Holders as shown
  • If you wanna use DailyRollingFileAppender or any other appenders that are not pre-loaded, please import org.apache.log4j.*
  • You can define variables like that
  • You can use different environment settings
import org.apache.log4j.*
import grails.util.Holders
myconfig {
myvariable {
workdir = 0
}
}
log4j = {
def pattern = new PatternLayout("[%p] [%c{3}] %m%n")
appenders {
appender new DailyRollingFileAppender(
name:"file",
file:"${Holders.config.myconfig.myvariable.workdir}/app.log",
layout: pattern,
datePattern: "'.'yyyy-MM-dd")
rollingFile name:"stacktrace",
file:"${Holders.config.myconfig.myvariable.workdir}/stacktrace.log",
maxFileSize:'100KB'
console name:"stdout",
layout: pattern
}
root {
environments {
production {
error "file"
}
development {
error "file", "stdout"
}
}
}
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 integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'org.springframework',
'org.hibernate',
'grails.plugins.springsecurity',
'groovyx.net.http'
all 'grails.app'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment