Advanced Logging

What is the variable 'log'?

The log variable is injected into every ScriptRunner inline script, and its value is equivalent to:

groovy
def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")

log is an instance of a Logger.

Using your own logger

It might be preferable to use your own logger so that you can adjust logging levels separately from ScriptRunner as a whole.

In an inline script, or file, you can do this using the following code:

groovy
import org.apache.log4j.Logger def log = Logger.getLogger("com.acme.workflows") log.warn("Workflow function running...")

If you use classes the simplest way to get a logger is to use the @Log4j annotation:

groovy
package com.acme.workflows import groovy.util.logging.Log4j @Log4j class Foo { void utilityMethod() { log.warn "Foo.utilityMethod" } }

In the above example, the log instance is automatically created and will have the category com.acme.workflows.Foo, that is, the fully qualified class name.

This is the best way of logging, as it will automatically wrap calls to the logger in the relevant guarding function, e.g. if (log.isDebugEnabled()) {log.debug(…​)}

Bitbucket uses log4j 1x, if browsing the documentation be sure you are not looking at the documentation for log4j 2x.

On this page