Log streaming and replay
Log streaming for Shopify Functions enables faster development, testing, and debugging of functions by bringing function execution logs to Shopify CLI. You can also replay function executions locally using input from these logs.
This guide describes how you can enable and use this beta functionality to improve your function development workflow.
Enabling log streaming and replay
Anchor link to section titled "Enabling log streaming and replay"The SHOPIFY_CLI_ENABLE_APP_LOG_POLLING
environment variable enables beta log streaming and replay functionality on Shopify CLI 3.63
or higher.
To enable function logs in the output of shopify app dev
, and use the shopify app function replay
command, set SHOPIFY_CLI_ENABLE_APP_LOG_POLLING
to 1
:
Shopify CLI commands and workflow
Anchor link to section titled "Shopify CLI commands and workflow"The log streaming and replay beta enhances Shopify CLI to improve the testing and debugging of functions:
- Function executions on your development store are output in
shopify app dev
, and their details are written to a local file. - The
shopify app function replay
command can re-execute your function locally, using the input from these logged executions.
The following steps describe the use of these commands in a typical workflow:
Use
shopify app dev
during the development of your function to test your function on a development store. The output ofshopify app dev
will now include function executions.Open the log file to see the details of the function execution, including input and output:
- If your terminal supports hyperlinks, then click Open log file to open the file.
- If your terminal doesn't support hyperlinks, then use the output file path to open the file.
Add debugging output to your function by writing to
STDERR
. For example, useconsole.log
in JavaScript, oreprintln!
in Rust. This logging will be included in the output ofshopify app dev
.For faster debugging of function output, open a new terminal and use the
shopify app function replay
command to execute your function with the function runner:- Choose an option from the list of recently logged function executions.
- Iterate your function code until it outputs the desired value. As you make changes to your function code,
replay
will rebuild and re-execute it.
To enable step-debugging in your native toolchain, create unit tests using the function input JSON obtained in the function log file.