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, see Setting levels for logging, metrics, and tracing.
Note
Before you can begin logging messages, you must set up an event table. For more information, see Event table overview.
You can access log messages by executing a SELECT command on the event table. For more information, see Viewing log messages.
For general information about setting up logging and retrieving messages in Snowflake, see 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');