I'm using Grails 2.2.4 with log4j configured in a rather standard way (http://grails-dev.blogspot.com/2012/09/setting-up-log4j-configuration-in.html) and it works very well (details at the end of the question).
I would love to have complete information about anything that happens to objects with particular class in a separate files, so I'd like to be able to do something like configure log4j to log to custom file at runtime, but I can't figure out how to do this in grails. It would be great to do something like
package com.mydomain.service
import org.apache.commons.logging.LogFactory
class SampleService {
private static final log = LogFactory.getLog(this)
def index(Long id) {
log.setFileName("object-${id}.log")
log.info("The log message.")
}
}
(I know method setFileName doesn't exist; I'm talking about the general approach) Is it even possible?
And, if it is possible, can you tell me anything about performance? Will logging around 500 (< 1000 lines long) files a day slow down the execution of the application?
Thanks in advance.
My log4j configuration:
Within the code I log messages like this:
package com.mydomain.service
import org.apache.commons.logging.LogFactory
class SampleService {
private static final log = LogFactory.getLog(this)
def index() {
log.info("The log message.")
}
}
with config file containing
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.springframework',
'org.hibernate',
'groovyx.net.http'
all 'myApp'
}