User Tools

Site Tools


logging

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
logging [2017/05/08 08:41]
pawel created
logging [2019/05/27 15:59] (current)
root [Script Runner Console to ping a server]
Line 3: Line 3:
 You can add script runner logging to any script by adding code to your script. The log will be displayed both in catalina.out log file and in the script step (although this is delayed). To add the logging, add the following to your script: You can add script runner logging to any script by adding code to your script. The log will be displayed both in catalina.out log file and in the script step (although this is delayed). To add the logging, add the following to your script:
  
-<code>+<code java>
 import org.apache.log4j.Logger import org.apache.log4j.Logger
 import org.apache.log4j.Level import org.apache.log4j.Level
Line 10: Line 10:
 log.setLevel(Level.DEBUG) log.setLevel(Level.DEBUG)
      
-log.debug "foo bar"+log.debug("foo bar"+myVariable)
 </code> </code>
  
 +==== ScriptRunner Console script to ping a server ====
 +If you want to run a query to ping a server, or IP address, you can use the following script replacing 8.8.4.4 with the server ip or name that you're interested in:
 +<code java>
 +import org.apache.log4j.Logger
 +import org.apache.log4j.Level
 + 
 +def log = Logger.getLogger("com.acme.CreateSubtask")
 +log.setLevel(Level.DEBUG)
 + 
  
 +def proc = 'ping -c 3 8.8.4.4'.execute()
 +proc.waitFor()
 +def output = proc.text
 +println "Ping ${proc.exitValue() == 0 ? 'OK' : 'NOT OK'}"
 +
 +log.debug("Ping output: "+output)
 +</code>
 +
 +==== Message to the end user ====
 +
 +<code java>
 +import com.onresolve.scriptrunner.runner.util.UserMessageUtil
 + 
 +// Successful Action Message (green)
 +UserMessageUtil.success("Created two sub-tasks to be approved")
 + 
 +// Warning message (yellow)
 +UserMessageUtil.warning("Failed to push issue to downstream system, will try again later")
 + 
 +// Error message (red)
 +UserMessageUtil.error("Failed to reopen all linked issues")
 +</code>
logging.1494247312.txt.gz ยท Last modified: 2017/05/08 08:41 (external edit)