Advanced Logging
Learn our advanced concepts for logging in the app.
What is the variable 'log'?
The log variable is injected into every ScriptRunner inline script, and its value is equivalent to:
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:
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:
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.
if (log.isDebugEnabled()) {log.debug(…)}Log Levels
A log message is printed if the logging level is the same or higher than the configured level for that category.
The default log level for most categories is WARN. Take a note of the default log level before making any changes. Therefore, if you want to use log.debug, the category level must be set to DEBUG or TRACE.
Temporarily enable ScriptRunner logging under in the Administration menu. Set the com.onresolve package to DEBUG under Default Loggers.
You can change the logging level permanently by adjusting the log4j.properties files - see the Atlassian Confluence Logging Levels documentation.