I was fiddling with grails logging for a long time and I was doing it again and again and again... not very DRY. So here is how it's good for me for most projects. To the console are errors only, in dev mode a simple log file at debug level and in production a daily rolling log file at info level.
// log4j configuration
log4j = {
appenders {
console name:'console', threshold:org.apache.log4j.Level.ERROR
file name:'file', file: './myapp.log', threshold: org.apache.log4j.Level.DEBUG, layout: pattern(conversionPattern: "%d{ISO8601}\t%p\t%c:%L\t%m%n")
}
environments {
production {
appenders {
console name:'console', threshold: org.apache.log4j.Level.ERROR
appender new org.apache.log4j.DailyRollingFileAppender(name:"file", fileName:"/var/log/myapp.log",
datePattern: '\'_\'yyyy-MM-dd', layout:pattern(conversionPattern: '%d{ISO8601}\t%p\t%c:%L\t%m%n'),
threshold:org.apache.log4j.Level.INFO)
}
}
}
// trace "org.hibernate.SQL",
// "org.hibernate.type"
debug 'grails.app.service',
'grails.app.controller'
'grails.app.tagLib'
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',
'org.apache.commons.digester',
'net.sf.ehcache.hibernate',
'org.apache.tomcat',
'org.apache.catalina',
'net.sf.ehcache',
'org.apache.coyote',
'org.apache.commons.beanutils'
warn 'org.mortbay.log'
root {
debug 'console','file'
additivity = false
}
}
// log4j configuration
log4j = {
appenders {
console name:'console', threshold:org.apache.log4j.Level.ERROR
file name:'file', file: './myapp.log', threshold: org.apache.log4j.Level.DEBUG, layout: pattern(conversionPattern: "%d{ISO8601}\t%p\t%c:%L\t%m%n")
}
environments {
production {
appenders {
console name:'console', threshold: org.apache.log4j.Level.ERROR
appender new org.apache.log4j.DailyRollingFileAppender(name:"file", fileName:"/var/log/myapp.log",
datePattern: '\'_\'yyyy-MM-dd', layout:pattern(conversionPattern: '%d{ISO8601}\t%p\t%c:%L\t%m%n'),
threshold:org.apache.log4j.Level.INFO)
}
}
}
// trace "org.hibernate.SQL",
// "org.hibernate.type"
debug 'grails.app.service',
'grails.app.controller'
'grails.app.tagLib'
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',
'org.apache.commons.digester',
'net.sf.ehcache.hibernate',
'org.apache.tomcat',
'org.apache.catalina',
'net.sf.ehcache',
'org.apache.coyote',
'org.apache.commons.beanutils'
warn 'org.mortbay.log'
root {
debug 'console','file'
additivity = false
}
}
Keine Kommentare:
Kommentar veröffentlichen