Logging in Groovy script
Hi,
Is there a way to enable logger in Groovy Script? I want to print Groovy script response in the logger file.
Thanks!
Hi,
Is there a way to enable logger in Groovy Script? I want to print Groovy script response in the logger file.
Thanks!
Hi @mvelicheti,
Groovy console provides OOTB logger. So there is no need to add any imports, or create logger instance manually.

As you can see it is available under log variable. Below is sample code that presents how to use it.
log.info "Info message"
log.error "Error message"
log.debug "Debug message"
log.trace "Trace message"
in error.log file you can expect entries like this
*INFO* [127.0.0.1 [1685283081856] POST /bin/groovyconsole/post.json HTTP/1.1] groovyconsole Info message
*ERROR* [127.0.0.1 [1685283081856] POST /bin/groovyconsole/post.json HTTP/1.1] groovyconsole Error message
*DEBUG* [127.0.0.1 [1685283081856] POST /bin/groovyconsole/post.json HTTP/1.1] groovyconsole Debug message
*TRACE* [127.0.0.1 [1685283081856] POST /bin/groovyconsole/post.json HTTP/1.1] groovyconsole Trace message
Please be aware that what will be logged, depends also on error.log level. You can change log level that will be stored under error.log under /system/console/slinglog
Last but not least, log object represents org.slf4j.Logger class, so you can use any method exposed by it.
In case you would like to collect groovy console logs in separate/custom file. This can be done like this:

Base on above configuration groovy console logs will be stored under groovy-console.log file.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.