4053 views

Workflow Logging Overview

 

Goals
  • Introduction to Workflow Logging
  • Logging from the Engine
  • Logging from the Activity
  • Writing customized Log messages in Script

 

Logging in ServiceNow Workflow

ServiceNow Workflow provides logging in a log exclusive to workflows. It is separate from the System log that is specific to a currently executing Workflow Context.

Logging is useful for debugging and to trace progress through a workflow.

ServiceNow Workflow is part of the Glide Script Engine and is invoked with the insert, update, delete or cancel of a Glide record. Log entries in the Workflow Log indicate whether they were entered from the Engine or from the Activity.

The level of logging present in the Workflow Context is configurable by properties. 

  

Add a log message activity
The first exercise demonstrates the default logging behavior in the workflow. 
  1. Return to the Workflow Editor by re-selecting the ServiceNow tab.
  2. Click New on the workflow canvas header.
  3. Fill out the form as follows.

    Name: K14 Logging Demo.

    Table: Global.
     
  4. Click the Submit button.


     
  5. Expand the Utilities folder of the Activities Tree.
  6. Find the Log Message Activity in the Utilities folder.
  7. Hold the mouse down and drag the Activity onto the canvas.
  8. Hover the Activity over the transition line until the line turns blue.
  9. Release the mouse. The New Activity form displays.
  10. Fill out the form as follows.

    Name: K14 Log Message
    Message: This is a message in the Log Message Activity.


     
  11. Click the Submit button. 

    Your workflow should look like this:


     
  12. Find the Log Trace Message Activity in the Utilities folder.
  13. Hold the mouse down and drag the Activity onto the canvas.
  14. Hover the activity over the transition line between Log Message and End until the line turns blue.
  15. Release the mouse.
  16. Fill out the form as follows:

    Name: K14 Log Trace Message.
     
  17. Click Submit.

    Your workflow should look like this:


     
  18. Find the Run Script Activity in the Utilities folder.
  19. Hold the mouse down and drag the Activity onto the canvas.
  20. Hover the activity over the transition line between the Log Trace Message and End Activities until the line turns blue.
  21. Release the mouse.

    Fill out the form as follows:

    Name: K14 Log Message from inside Run Script
    Script:
    workflow.debug(‘Logging DEBUG from inside a script’);
    workflow.info(‘Logging INFO from inside a script’);

     
  22. Click the Submit button.

    Your workflow should look like this:


     
  23. Click the green Play button in the header of the canvas.


     
  24. Click the Submit button.



    QUESTION: What does the blue coloring of the activities tell us? 

 

Review logging output

  1. Return to the main ServiceNow tab. 
  2. In the Applications Select the All Contexts module in the Workflow. 


     
  3. Select the Workflow Execution: K14 Logging Demo context.


     
  4. Select the Workflow Log tab.

    Notice the Source column:



    • ENGINE is a message that is coming from within the Workflow Engine.
    • ACTIVITY is a message that is coming from the JavaScript within a Workflow Activity.

    Notice the messages:


     

    (1) The first ACTIVITY message is the output of the Log Message Activity.
    (2) The next three messages are the output of the Trace Message Activity. The Trace Message Activity logs the name assigned to the Activity, the event that the workflow is transitioning on, and the ID of the Workflow Context.
    (3) The third message is the INFO message written in the Script field of the Run Script activity.

    QUESTION: What message is missing from this log?

    The level of verbosity in the Workflow Log is configurable by properties.
     
  5. Workflow > Properties.


     
  6. Check the property Log details of workflow actions. This property sets the level of log messaging.
  7. Check Log workflow debug messages. It sets the level of log messaging while debugging is activated.
  8. Return to the Workflow Editor and close the tab.
  9. Open the K14 Logging Demo workflow. Note that the workflow is Checked out.
  10. Re-execute the workflow using the green Play arrow.


     
  11. Return to the main ServiceNow tab.
  12. Workflow > All Contexts.
  13. Find and select the most recently run K14 Logging Demo workflow.
  14. Select the Workflow Log tab.

    Your list should look like this:

     

    NOTE: The Actual number of Workflow Log messages will vary.

    Notice:
    • The dramatic increase in Workflow Log entries.
    • The mix of Debug and Information messages.
    • How much information is coming from the ENGINE!
     
     
Search the list for run script logging
Do these next steps using the List filter. 
  1. Select: Go to Message.
  2. Type: from Run Script.


     
  3. Click the Search icon (magnifying glass).

    Your list should look like this:



    Notice the previously missing Debug message from the Run Script Activity is now in the Workflow Log.
     

NOTE:  The Workflow Logging Properties apply to all running Contexts. Use them only when needed for debugging or testing to optimize performance on your instance. 


Summary


The Workflow Engine provides configurable logging options using the Workflow Properties.

Log messages indicate their source of the message. A Message log entry comes from either the ENGINE or from within an ACTIVITY.

Log entries can be made into the Context Workflow Log using the Log Message Activity, the Log Trace Activity and directly through JavaScript.

As the Workflow logging gets more verbose, the list filter is quick way to locate messages. 

Article Information

Last Updated:2015-05-02 10:15:24
Published:2014-05-16