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.
There are two main ways to do logging in Canvas:
...
Block output logging, which can be customized with a search model
...
When a block runs, its full output response (as shown in the Response tab) is automatically logged and stored by Canvas. The logged output can be indexed for easy searching using a search model.
Canvas also enables in-code logging using the helper function logger.log()
Info |
---|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
In this article we will describe how to set up logging using both methodsa search model, and how to use logger.log() for custom logging.
See also the related article for how to search the stored logs: Searching logs
...
When you click the icon you will be presented with a hierarchy of fields, from which , based on the response that was last outputted by the block. (You may need to run the block first, to generate an output response.)
Here you can select the relevant fields to logyou wish to be able to search in the logs:
...
In this case we have only selected the “badgeNo” field, as we just need to log which employees were transferred.
...
which will let us search for the all block responses where the badgeNo was present.
See this article for info on how to search stored logs: Searching logs
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 also the related this article for info on how to search the stored logs: Searching logs