Writing logs
To emit a log line from your Cloud Function, write to standard output or standard error.
Node.js
Useconsole.log()
and console.error()
:
Python (Beta)
For example, useprint()
or the logging
module:
Go (Beta)
- Logs to standard output have the
INFO
log level. - Logs to standard error have the
ERROR
log level. - Internal system messages have the
DEBUG
log level.
Viewing logs
Using the command-line tool
Logs for Cloud Functions are viewable in the Stackdriver Logging UI, and
via the gcloud
command-line tool.
To view logs with the gcloud
tool, use the
logs read
command:
gcloud functions logs read
To view the logs for a specific function, provide the function name as an argument:
gcloud functions logs read FUNCTION_NAME
You can even view the logs for a specific execution:
gcloud functions logs read FUNCTION_NAME --execution-id EXECUTION_ID
For the full range of log viewing options, view the help for logs read
:
gcloud functions logs read -h
Using the Logging dashboard
You can also view logs for Cloud Functions from the GCP Console.
Using the Logging API
Logs can also be written and retrieved through the Logging API. The Stackdriver Logging Client Libraries provide an idiomatic interface to the Logging API:
Node.js
For more information, see the Node.js Client Library reference.Python (Beta)
For more information, see the Python Client Library reference.Go (Beta)
For more information, see the Go Client Library reference.Responding to logs
You can respond to Stackdriver-logged events by forwarding their logs to a Cloud Function. For more information, see the Second-Party Triggers with Stackdriver page.