Reputation: 9636
I want my grails application to log all debugs, stack traces, uncaught errors (500s etc) to be logged to a specific file myapp.log
in tomcat. At the moment everything is being logged to catalina.out
. Which isn't desirable as there might be other applications deployed on the Tomcat instance.
My config looks like this. I am using grails 2.2.4
log4j = {
appenders {
console name: "stdout", layout: pattern(conversionPattern: "%c{2} %m%n")
}
root {
info "stdout"
}
debug "com.myapp.mypackage",
"grails.app.controllers.com.myapp.mycontrollers"
}
Upvotes: 0
Views: 558
Reputation: 75671
I'd put this in an environments
block to make sure it only applies to the production environment. You can easily add a file appender in the appenders
section, and the Grails docs show how to configure it as a rolling appender to create new files every day, or once a file has reached a maximum size, etc. 'Attach' the appender to the root
level in place of the console
appender:
environments {
production {
log4j = {
appenders {
console name: "stdout",
layout: pattern(conversionPattern: "%c{2} %m%n")
file name: 'mylog',
file: '/var/logs/mylog.log',
layout: pattern(conversionPattern: "%c{2} %m%n")
}
root {
info "mylog"
}
debug "com.myapp.mypackage",
"grails.app.controllers.com.myapp.mycontrollers"
}
}
}
Configuring logging using the Log4j DSL is pretty confusing, but the docs explain a lot and have a bunch of helpful examples: http://grails.org/doc/latest/guide/conf.html#logging
Upvotes: 3