Logging Messages in Snowflake Scripting

You can log messages from a function or procedure handler written in Snowflake Scripting by using the Snowflake SYSTEM$LOG, SYSTEM$LOG_<level> (for Snowflake Scripting) function. When you’ve set up an event table to store log entries, Snowflake stores log entries generated by your handler code in the table.

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.

Note

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.

Snowflake Scripting Example

Code in the following example uses the SYSTEM$LOG function to log messages at each of the supported levels. Note that a message logged from code that processes an input row will be logged for every row processed by the handler. If the handler is executed in a large table, this can result in a large number of messages in the event table.

-- The following calls are equivalent.
-- Both log information-level messages.
SYSTEM$LOG('info', 'Information-level message');
SYSTEM$LOG_INFO('Information-level message');

-- The following calls are equivalent.
-- Both log error messages.
SYSTEM$LOG('error', 'Error message');
SYSTEM$LOG_ERROR('Error message');


-- The following calls are equivalent.
-- Both log warning messages.
SYSTEM$LOG('warning', 'Warning message');
SYSTEM$LOG_WARN('Warning message');

-- The following calls are equivalent.
-- Both log debug messages.
SYSTEM$LOG('debug', 'Debug message');
SYSTEM$LOG_DEBUG('Debug message');

-- The following calls are equivalent.
-- Both log trace messages.
SYSTEM$LOG('trace', 'Trace message');
SYSTEM$LOG_TRACE('Trace message');

-- The following calls are equivalent.
-- Both log fatal messages.
SYSTEM$LOG('fatal', 'Fatal message');
SYSTEM$LOG_FATAL('Fatal message');
Copy