Here’s the translation of the Go logging example to Groovy, formatted in Markdown suitable for Hugo:
Our first example demonstrates logging in Groovy. The standard library provides straightforward tools for outputting logs from Groovy programs.
This example demonstrates various logging techniques in Groovy:
We start with the @Log annotation, which provides a simple way to add logging to a class.
We then show how to configure the logger’s output format using system properties.
The @Slf4j annotation is introduced, which provides more advanced logging capabilities.
We demonstrate error logging with exception information.
Parameterized logging is shown, which can be more efficient than string concatenation.
Finally, we show how to log to a custom output stream.
To run this program, save it as logging.groovy and use the groovy command:
The output will vary depending on your Groovy and SLF4J setup, but it should look something like this:
This example provides a basic introduction to logging in Groovy. In practice, you would typically configure your logging in more detail, possibly using a configuration file, and you might use a more full-featured logging framework like Logback or Log4j.