Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Logging in Groovy is based on the JDK logging facilities.
Please read the JDK logging documentation if you are new to the topic.

In order to enable tracing of how Groovy calls MetaMethods, use
the following settings:

in file %JAVA_HOME%/jre/lib/logging.properties or equivalent

  • make sure your log handler is configured to show level 'FINER' at least,
    e.g.

  • set MetaClass logging to 'FINER' at least,
    e.g.

  • set the appropriate Level for the Classes and optionally method names
    that you want to trace. The name for the appropriate logger starts with
    'methodCalls' and optionally ends with the method name,
    e.g.

Example:
with tracing enabled for all method calls a Groovy command line
script appears as follows (German locale)

@Log

You can annotate your classes with the @Log transformation to automatically inject a logger in your Groovy classes, under the log property. Four kind of loggers are actually available:

  • @Log for java.util.logging
  • @Commons for Commons-Logging
  • @Log4j for Log4J
  • @Slf4j for SLF4J

Here's a sample usage of the @Log transformation:

You can change the name of the logger by specifying a different name, for instance with @Log('myLoggerName').

Another particularity of these logger AST transformations is that they take care of wrapping and safe-guarding logger calls with the usual isSomeLevelEnabled() calls. So when you write log.info 'Car constructed', the generated code is actually equivalent to:

See Also

  • No labels