In BootStrap.groovy in my Grails 3.3.2 app I get the following exception when logging:
groovy.lang.MissingMethodException: No signature of method: ch.qos.logback.classic.Logger.info() is applicable for argument types: (org.apache.http.message.BasicStatusLine) values: [HTTP/1.1 200 OK]
Here is the log statement:
log.info(resp.statusLine)
I know I can work around this by calling toString() on the info method but that is not a good solution because I may have lots of log statements that I may need to fix to workaround previously valid code. Is there a bug opened for this issue?
Grails 3 uses Logback as the logging library, and it has support for variable replacement that makes logging much more efficient.
Often users log statements like
log.debug('found ' + items.size() + ' items: ' + items)
This is expensive because the expression is concatenated into a single String before calling debug()
, and if the level of that logger is not DEBUG or TRACE, then nothing will be logged, so if the concatenated String is large (or if this is called often) then that work is wasted. You can wrap the call in an enabled check:
if (log.isDebugEnabled()) {
log.debug('found ' + items.size() + ' items: ' + items)
}
but this clutters your code. With Logback though you're much better off doing this:
log.debug('found {} items: {}', items.size(), items)
Now you're just passing a simple String plus two args to interpolate at the specified positions, but only if the log statement is enabled for the logger's level. If not the call is almost a no-op.
For your logging statement, you should do this instead:
log.info('{}', resp.statusLine)
or
log.info('Status: {}', resp.statusLine)