- Categories:
System functions (System Information)
SYSTEM$GET_DBT_LOG¶
Returns logs for the specified run for a dbt Projects on Snowflake.
Use this function with the DBT_PROJECT_EXECUTION_HISTORY function to access dbt artifacts and logs programmatically.
Syntax¶
Arguments¶
query_idQuery ID of the run that you want logs for.
max_num_linesOptional. Maximum number of lines to return from the end of the
dbt.logfile. Defaults to1000.The combined size of the returned lines is capped at approximately 10 MB. If the lines you request exceed this limit, the function drops the oldest lines from the start of the result until it fits, so the output always reflects the most recent lines in the log.
Returns¶
The function returns up to max_num_lines lines from the end of the dbt.log file (1,000 lines by default). For full logs, download the archive ZIP file.
For more information and examples, see Access dbt artifacts and logs programmatically.
Access control requirements¶
This function includes only runs from workspaces and dbt Projects in which you have the following privileges:
OWNERSHIP, READ, or WRITE on workspaces
OWNERSHIP, USAGE, or MONITOR on dbt Projects
Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema.
For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.
For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.
Usage notes¶
This system function works only on dbt project objects; it isn’t available for workspaces.
Query IDs generated from CREATE DBT PROJECT or ALTER DBT PROJECT … ADD VERSION aren’t supported for this system function.
Direct querying of file content (for example, Query examples) isn’t supported.
If
query_idis NULL or not a dbt execution, you’ll get an error.dbt project results are available for up to 14 days.
Logs might be unavailable if a run times out, is canceled, or fails before files are uploaded. In such cases, runs appear as
UNHANDLED ERRORin dbt history, and these entries might not include logs.You can’t use this function to get logs for runs that are in progress because the logs file is only available after the run in complete.
Examples¶
The following example looks up the most recent dbt project object execution using DBT_PROJECT_EXECUTION_HISTORY and then fetches the logs for that execution using SYSTEM$GET_DBT_LOG, so you can inspect what happened during the execution.
Tip
Use function arguments such as DATABASE, SCHEMA, and OBJECT_NAME to filter results whenever possible. These filters are applied before the RESULT_LIMIT (default: 100 rows), so using them ensures you get the most relevant results rather than filtering a potentially truncated result set with a WHERE clause.
To retrieve more than the default 1,000 lines, pass a second argument specifying the maximum number of lines:
For more information, see Access dbt artifacts and logs programmatically.