Grails Logging - Only log my application, not grails specific junk
Starting from the default logging config, I added the root{} block to turn on debug level logging. And I added a method for my controllers...
log4j = {
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.mortbay.log'
debug 'grails.app.controller'
root {
debug()
}
}
And now I get debug alright. But I get it from everywhe开发者_Go百科re. All the startup junk that Grails goes through when doing a run-app, clearing cache, loading spring beans, etc. I want to configure this so the only logging I get is from my code. Is that even possible?
In your Config.groovy file, in a log4j section, define a log appender like this:
appender name: "appLog",
new org.apache.log4j.DailyRollingFileAppender(
threshold: org.apache.log4j.Level.INFO,
datePattern: "'.'yyyy-MM-dd",
file: "${logDirectory}/app.log",
layout: pattern(conversionPattern: '[%d{yyyy-MM-dd hh:mm:ss.SSS}] %p %c{5} %m%n'))
Let the root logger be the root, and log on the console:
root {
additivity = true
info stdout
}
And then add debug only to your app in a specific logger
debug additivity:true, appLog: "grails.app"
The grails Logging Section has been changing a lot, but is pretty much up to date now.
精彩评论