为日志、指标和跟踪设置级别¶
You can set the threshold levels for log messages, log events, trace data, or metrics data captured in an event table.
Each kind of telemetry data supports its own set of levels that are specific to its purpose. You can set these levels by using the parameter Snowflake provides for each. You can also set some levels using Snowsight, which represents the level parameters in a simplified way.
For each kind of telemetry data, you can do the following:
Set levels specific to that kind of data.
Set system-wide levels that are in effect unless overridden.
通过为会话或特定对象(例如过程和 UDFs)设置级别来替换系统范围级别。
Levels are represented as both session parameters and object parameters.
备注
You can use handler code to override the log level you set with SQL (as described in this topic) when your handler is written in Python. For more information, see 使用 Python 替换日志阈值级别.
范围¶
对于每种类型的遥测数据,您可以设置级别,使其在最符合您要求的范围内生效。在许多情况下,您可以通过在较小的范围内设置级别来覆盖在更大范围内设置的级别,如 Snowflake 如何确定有效级别 中所述。例如,您可能希望在账户范围内设置一组默认级别,然后为特定数据库中的对象设置不同的级别。
您可以在以下范围内设置每个级别:
- 账户:
为账户设置的级别在账户中的任何地方都有效,但在被对象或会话级别设置的级别覆盖的位置除外。
- 对象:
您可以为以下类型的对象设置遥测级别:
包含过程和函数的数据库或架构
存储过程
用户定义的函数 (UDF) 或用户定义的表函数 (UDTF)
Externally managed Apache Iceberg™ table with automated refresh configured
For example, to set the log level for log messages from logging APIs for a specific UDF, use ALTER FUNCTION to set the LOG_LEVEL parameter for that UDF. As another example, to set the default log level for all functions and procedures in a database, use ALTER DATABASE to set the LOG_LEVEL parameter on that database. As another example, to set the log event level for a specific externally managed Iceberg table with automated refresh configured, use ALTER ICEBERG TABLE to set the LOG_EVENT_LEVEL parameter on that table. Use ALTER <object> commands to set the LOG_EVENT_LEVEL parameter for other objects that emit log events (record type EVENT).
备注
您不能设置 Streamlit 对象的级别。但可以设置包含对象的数据库或架构的级别。
- 会话:
您可以为当前会话中对函数和过程的调用设置遥测级别。
级别¶
您可以为每种遥测数据设置以下级别:
- Log messages:
When you set a level, only log messages from logging APIs at that level and more severe levels are captured in an event table and visible in Snowsight. For example, setting the LOG_LEVEL parameter to WARN means that log messages at the WARN, ERROR, and FATAL levels are captured in the event table.
设置 LOG_LEVEL 参数。
- Log events:
When you set a level, only log events (record type EVENT) at that level and more severe levels are captured in an event table. Examples include events from Snowpipe, tasks, dynamic tables, Snowpark Container Services compute pools, Iceberg tables, and data governance tag activity.
Set the LOG_EVENT_LEVEL parameter.
- 衡量标准:
目前,您可以捕获所有指标数据,也可以不捕获任何指标数据。
设置 METRIC_LEVEL 参数。
- 跟踪:
您可以指定以下特征:
事件表中存储的跟踪事件数据的范围
设置 TRACE_LEVEL 参数。
是否在跟踪的 SQL 语句中捕获 SQL 文本
这是由 SQL_TRACE_QUERY_TEXT 参数决定的。有关更多信息,请参阅 SQL 语句跟踪。
需要的权限¶
要设置对象的级别,您必须使用已获授或继承本节所述权限的角色。
例如,以下示例中的代码授予使用 central_log_admin 角色的用户设置账户日志级别所需的权限:
有关权限的更多信息,请参阅 访问控制权限。
要修改的级别 |
要设置的参数 |
需要的权限 |
|---|---|---|
Log level (log messages) |
账户
对象
会话
|
|
Log event level |
账户
对象
会话
|
|
指标级别 |
账户
对象
会话
|
|
跟踪级别 |
账户
对象
会话
|
|
SQL 跟踪中的 SQL 文本 |
账户
|
设置遥测级别¶
您可以使用 SQL 或者在某些情况下使用 Snowsight 来设置遥测级别。在许多情况下,您可以通过在较小的范围内设置级别来覆盖在更大范围内设置的级别,如 Snowflake 如何确定有效级别 中所述。
设置级别之前,确认您拥有 具备所需权限的角色 的访问权限。
您可以使用 Snowsight 在账户级别设置遥测级别。
Sign in to Snowsight.
In the navigation menu, select Monitoring » Traces & logs.
在 Traces & Logs 页面上,选择 Set Event Level。
对于:ui:
Set logging & tracing for,请从以下任一选项中选择所需的范围:Account
数据库和(可选)架构
选择要调整的遥测数据级别。
All Events
On 开启对各种遥测数据的收集;Off 关闭对各种数据的收集。
Traces
On 将跟踪数据收集设置为
ALWAYS;Off 将跟踪数据收集设置为OFF。有关级别的更多信息,请参阅 TRACE_LEVEL。Logs
On 将日志数据收集设置为
INFO。有关级别的更多信息,请参阅 LOG_LEVEL。Metrics
On 将跟踪数据收集设置为
ALL;Off 将跟踪数据收集设置为NONE。有关级别的更多信息,请参阅 METRIC_LEVEL。
您可以使用 SQL 为账户和数据库、函数和过程等对象设置遥测级别。
使用 ALTER ACCOUNT 命令根据要收集的遥测数据设置相应的参数。
以下示例将账户的日志级别设置为 ERROR:
要设置对象的 LOG_LEVEL 参数,请使用 ALTER <object> 命令。
以下示例为数据库 db 中所有函数和过程将日志级别设为 ERROR。该示例为 UDF f1(int) 将此级别替换为 WARN。
有关 Snowflake 如何在不同对象上设置 LOG LEVEL 时确定有效日志级别的详细信息,请参阅 Snowflake 如何确定有效级别。
要为当前会话设置 LOG_LEVEL 参数,请使用 ALTER SESSION 命令。
如果针对当前会话以及该会话中调用的函数和过程将级别参数设置成了不同级别,则 Snowflake 将确定要使用的有效级别。请参阅 Snowflake 如何确定有效级别。
Snowflake 如何确定有效级别¶
You can override the telemetry level-related parameters (for both objects and sessions) by using a hierarchy of levels.
例如,您可以将账户的级别设置为一个值,然后通过为层次结构中较低的对象设置级别来替换该级别。
会话和对象级别参数的层次结构说明如下。
对于 会话参数,层次结构为账户 » 用户 » 会话。
这意味着您可以为账户设置参数、替换用户的账户级参数,并替换当前会话的用户级参数。
对于 对象参数,层次结构为账户 » 数据库 » 架构 » 对象。
这意味着您可以为账户设置参数、替换数据库或架构的账户级参数,并替换该数据库或架构中的特定存储过程以及 UDFs 的数据库级参数或架构级参数。
For example, the LOG_LEVEL for log messages for a function overrides the LOG_LEVEL for the account that contains the function. If the LOG_LEVEL for the account is FATAL and the LOG_LEVEL for the Java UDF in the account is INFO, the effective LOG_LEVEL is INFO (the level for the function, not the account):
如果同时在会话和对象参数层次结构中设置了级别参数,则使用最详细的级别。
For LOG_LEVEL (log messages from logging APIs), the following table lists examples of how parameters set on the session and object affect the log level used.
会话的值
对象、架构、数据库或账户的值
LOG_LEVEL Used
(未设置)
WARNWARNDEBUG(未设置)
DEBUGWARNERRORWARNINFODEBUGDEBUG(未设置)
(未设置)
OFFThe same precedence rules apply to LOG_EVENT_LEVEL for log events (record type EVENT).
对于指标级别 –
ALL替换NONE。对于跟踪级别 –
ALWAYS替换ON_EVENT和OFF;ON_EVENT替换OFF。