Logging Messages in JavaScript

You can log messages from a function or procedure handler written in JavaScript by using the snowflake object included with the Snowflake JavaScript API. When you’ve set up an event table to store log entries, Snowflake stores log entries generated by your handler code in the table. For reference about the JavaScript API, see JavaScript Stored Procedures API.

Before logging from code, be sure you have the logging level set so that the messages you want are stored in the event table. For more information, refer to Setting Log Level.


Before you can begin logging messages, you must set up an event table. For more information, refer to Setting up an Event Table.

You can access log messages by executing a SELECT command on the event table. For more information, refer to Accessing Logged Message Data.

For general information about setting up logging and retrieving messages in Snowflake, refer to Logging Messages from Functions and Procedures.

Code in the following example uses the included snowflake object to log messages at each of the supported levels. Note that a message logged from a method that processes an input row will be logged for every row processed by the UDF. If the UDF is executed in a large table, this can result in a large number of messages in the event table.

snowflake.log("info", "Information-level message");
snowflake.log("error", "Error message");
snowflake.log("warn", "Warning message");
snowflake.log("debug", "Debug message");
snowflake.log("trace", "Trace message");
snowflake.log("fatal", "Fatal message");