Here is a thought, you didn t ask this exactly but the same question was asked on the grails user group. I am posting my answer here as well, to spread the knowledge.
If you are explicitly saying def log = org.apache.commons.logging.LogFactory.getLog(this) in your classes rather than relying on dependency injection as was explained on the grails user group you can mock the getLog on the LogFactory.
The below is taken from grails.tests.MockUtils.mockLogging and modified to return the logger.
class LoggingEnabledTestCase extends GrailsUnitTestCase {
protected void setUp() {
super.setUp()
registerMetaClass(org.apache.commons.logging.LogFactory)
org.apache.commons.logging.LogFactory.metaClass. static .getLog = {instance ->
// This is taken from grails.tests.MockUtils and slightly changed to return a logger.
// Get the name of the class + the last component of the package
// (if it the class is in a package).
def pos = instance.class.name.lastIndexOf( . )
if (pos != -1) pos = instance.class.name.lastIndexOf( . , pos - 1)
def shortName = instance.class.name.substring(pos + 1)
// Dynamically inject a mock logger that simply prints the
// log message (and optional exception) to stdout.
def mockLogger = [
fatal: {String msg, Throwable t = null ->
println "FATAL (${shortName}): $msg"
if (t) {
println " Exception thrown - ${t.message}"
}
},
error: {String msg, Throwable t = null ->
println "ERROR (${shortName}): $msg"
if (t) {
println " Exception thrown - ${t.message}"
}
},
warn: {String msg, Throwable t = null ->
println "WARN (${shortName}): $msg"
if (t) {
println " Exception thrown - ${t.message}"
}
},
info: {String msg, Throwable t = null ->
println "INFO (${shortName}): $msg"
if (t) {
println " Exception thrown - ${t.message}"
}
},
debug: {String msg, Throwable t = null ->
println "DEBUG (${shortName}): $msg"
if (t) {
println " Exception thrown - ${t.message}"
}
},
trace: {String msg, Throwable t = null -> },
isFatalEnabled: {-> true},
isErrorEnabled: {-> true},
isWarnEnabled: {-> true},
isInfoEnabled: {-> true},
isDebugEnabled: {-> true},
isTraceEnabled: {-> false}] as Log
return mockLogger
}
}
protected void tearDown() {
super.tearDown()
}
}