[logback-user] Hiding Groovy language internal methods in Logback log files, to locate the "real" call to the logger

Christopher BROWN brown at reflexe.fr
Thu Jan 22 09:47:18 CET 2015


I'll start with a quick clarification, to avoid confusion: my question
relates to usage of Logback loggers via SLF4J (and, sometimes but not
always, also via the Log4J-to-SLF4J bridge) from Groovy code, and is not
about configuring Logback using Groovy (as it happens, we configure Logback
directly via the API, and not using configuration files).

In Groovy code, it's perfectly fine to write something like this:

def somevar = 'world'
log.debug "Hello ${somevar}"

The "debug" method call doesn't need parentheses because there's only one
parameter (and, furthermore, it's using the "GString" interpolation
approach).  Our application can be extended with Groovy scripts by our
customers, so we find this in their code when helping them customize.

So we often end up with entries like this (obviously simplified here) in
our log files:

2015-01-20 17:55:17,715 DEBUG - [Category$debug.call:?] Hello world

So the class name and method name being reported as the location are
actually the locations of the Groovy call site, and not the actual
"log.debug" call.

Some sort of general capability along the lines of LOGBACK-540 might be
helpful, but here the requirement is just to truncate the topmost "internal
Groovy" stack frame (or frames) so that the reported location is the call
into the logger in the script.  Is this possible, and how could it be
achieved?  I seem to remember an example of this a long time ago, but I
can't find it amongst all the search results referring to Groovy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20150122/76817100/attachment.html>

More information about the Logback-user mailing list