<service_name>!SPCS_GET_LOGS¶

Returns the logs that Snowflake collected from containers of the specified service. For more information, see Access container logs.

Note

The function is supported only for services and jobs created in release 9.20 or later.

See also:

Monitoring Services

Syntax¶

<service_name>!SPCS_GET_LOGS(
  [ START_TIME => <constant_expr> ],
  [ END_TIME => <constant_expr> ] )
Copy

Arguments¶

START_TIME => constant_expr

Start time (in TIMESTAMP_LTZ format) for the time range from which to retrieve logs. For available functions to construct data, time, and timestamp data, see Date & time functions.

If the START_TIME isn’t specified, it defaults to 1 day ago.

END_TIME => constant_expr

End time (in TIMESTAMP_LTZ format) for the time range from which to retrieve logs.

If END_TIME isn’t specified, it defaults to the current timestamp.

Output¶

Each row in the output corresponds to one logged event in the event table. Each line that your service outputs to stdout or stderr results in one row in the output.

The function returns the following columns:

Column

Data Type

Description

TIMESTAMP

TIMESTAMP_NTZ

Universal Coordinated Time (UTC) timestamp when Snowflake collected the log from the container. This value maps to the TIMESTAMP column in the event table.

INSTANCE_ID

NUMBER

ID of the job service instance. This value maps to the snow.service.instance field in the RESOURCE_ATTRIBUTES column in the event table.

CONTAINER_NAME

VARCHAR

Name of the container. This value maps to the snow.service.container.name field in the RESOURCE_ATTRIBUTES column in the event table.

LOG

VARCHAR

Log Snowflake collected from your application container. This value maps to the VALUE column in the event table.

RECORD_ATTRIBUTES

OBJECT

Addition information about the log. For example, the log stream — stderr or stdout — from where the log was collected. This value maps to the RECORD_ATTRIBUTES column in the event table.

Access control requirements¶

A role used to execute this operation must have the following privileges at a minimum:

Privilege

Object

Notes

OWNERSHIP

Service

The USAGE privilege on the parent database and schema are required to perform operations on any object in a 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¶

  • It can take a few minutes before your container logs show in the output.

Examples¶

Retrieve the logs that Snowflake collected from containers of the my_test_job job over the past day.

SELECT * FROM TABLE(my_test_job!SPCS_GET_LOGS());
Copy

Example output:

+-------------------------+-------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+
| TIMESTAMP               | INSTANCE_ID | CONTAINER_NAME | LOG                                                                                                                                                                 | RECORD_ATTRIBUTES          |
|-------------------------+-------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------|
| 2025-06-26 00:23:40.281 |           0 | main           | job-tutorial - INFO - Job finished                                                                                                                                  | {                          |
|                         |             |                |                                                                                                                                                                     |   "log.iostream": "stdout" |
|                         |             |                |                                                                                                                                                                     | }                          |
| 2025-06-26 00:23:38.787 |           0 | main           | job-tutorial - INFO - Executing query [select current_time() as time,'hello'] and writing result to table [results]                                                 | {                          |
|                         |             |                |                                                                                                                                                                     |   "log.iostream": "stdout" |
|                         |             |                |                                                                                                                                                                     | }                          |
| 2025-06-26 00:23:38.787 |           0 | main           | job-tutorial - INFO - Connection succeeded. Current session context: database="TUTORIAL_DB", schema="DATA_SCHEMA", warehouse="TUTORIAL_WAREHOUSE", role="TEST_ROLE" | {                          |
|                         |             |                |                                                                                                                                                                     |   "log.iostream": "stdout" |
|                         |             |                |                                                                                                                                                                     | }                          |
| 2025-06-26 00:23:36.852 |           0 | main           | job-tutorial - INFO - Job started                                                                                                                                   | {                          |
|                         |             |                |                                                                                                                                                                     |   "log.iostream": "stdout" |
|                         |             |                |                                                                                                                                                                     | }                          |
+-------------------------+-------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+

Retrieve the logs that Snowflake collected from containers of the my_test_job job over the past three days.

SELECT * FROM TABLE(my_test_job!SPCS_GET_LOGS(START_TIME => DATEADD('day', -3, CURRENT_TIMESTAMP())));
Copy

Retrieve the logs for the my_test_job job instance 0 in the container named main. As shown in the following example, if you omit the START_TIME and END_TIME arguments, the function retrieves the logs for the past day:

SELECT * FROM TABLE(my_test_job!SPCS_GET_LOGS())
WHERE instance_id = 0 AND container_name = 'main';
Copy