• Ready for review
  • Configuring logging

    Canvas comes with a suite of powerful logging tools built-in, giving you full, customizable access to all relevant historical data, validation errors, error messages, etc.

    When a block runs, its full output response (as shown in the Response tab) is automatically logged and stored by Canvas for 30 days.

    In this article we will explain how you can configure the logging to suit your needs, by using a search model for easy searching, or with in-code logging using the helper function logger.log()

    See also the related article for how to search the stored logs: Searching logs

     

    • Canvas automatically logs the output responses generated by each block and stores it for 30 days.

    • A block search model lets you select which fields in the block output should be indexed for easy searching. For example employee numbers, order numbers, etc., to enable lookup on those fields.

    • Custom information can be logged using logger.log() in the block code. This lets you to log your own messages, create conditional logging logic, log validation errors, error responses, etc.

     

    Setting up a block Search Model

    To set up a search model, select the block you want to log information for, and head to the Response tab.

    Here you will find an icon to “Update Search Model” (you may need to scroll down inside the Response tab to see the icon):

    (Note: You may need to scroll down inside the response tab to see the icon. There are two scroll bars on the right side, visible when you hover the cursor over the area. This UI will change in a future update.)

     

    When you click the icon you will be presented with a hierarchy of fields, based on the response that was last outputted by the block. (You may need to run the block first, to generate an output response.)

    In the screenshot we selected the “badgeNo”, “givenName”, and “familyName” fields. This will ensure that these three fields are searchable in the logs going forward (logs created after the search model was defined).

    Press the Save icon after making your selections. 💾

     

    When you search the logs (using search option “By response”) you will see the fields you selected as options in the search settings:

    The search model fields will be searchable starting from the date the model was set up.

    Using logger.log()

    The logger.log() function can be used in the code for any block. The function accepts both strings and objects, but objects will be stringified. Null and undefined values will be logged as empty strings.

    It is a good idea to make sure that the strings you log have a unique format that allow for easy searching.

    In the example above, one can easily search through the logs to find all ”Validation error”, or “Validation error, badgeNo 12345”, because those parts of the string are fixed.

    If the errors were instead stored without a prefix, just using logger.log(err), it would not be possible to search for all validation errors for just one employee, and it would be difficult to tell the log type apart from other uses of logger.log().

     

    See this article for info on how to search stored logs: Searching logs