Script Logging
The script task execution API (IScriptExecutionContext) provides a script logger to log events during an execution. The method
getScriptLogger() returns the logger. The logger can be used to log Errors, Warnings, Debug messages etc.
You shall always prefer the usage of the logger before using the println() of stdout or stderr.
In any code block without direct access to the script API, you can write the following code to access the logger: ScriptApi.scriptLogger
Usage of the script logger
scriptTask("TaskName"){
code{
// Use the scriptLogger to log messages
scriptLogger.info "My script is running"
scriptLogger.warn "My Warning"
scriptLogger.error "My Error"
scriptLogger.debug "My debug message"
scriptLogger.trace "My trace message"
// Also log an Exception as second argument
scriptLogger.error("My Error", new RuntimeException("MyException"))
}
}
ILogger also provides a formatting syntax for the format String. The syntax is {IndexNumber} and
the index of arguments after the format String.
It is also possible to use the Groovy GString syntax for formatting.
Usage of the script logger with message formatting
scriptTask("TaskName"){
code{ argument ->
// Use the format methods to insert data
scriptLogger.info("My script {0} with:{1}", scriptTask, argument)
}
}
Usage of the script logger with Groovy GString message formatting
scriptTask("TaskName"){
code{ argument ->
// Use the Groovy GString syntax to insert data
scriptLogger.info "My script $scriptTask with: $argument"
}
}