Writing and Viewing Logs

Writing logs

To emit a log line from your Cloud Function, use either console.log, or console.error.


exports.helloWorld = function helloWorld (event, callback) {
  console.log('I am a log entry!');

  • console.log() commands have the INFO log level.
  • console.error() commands 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 either in the Stackdriver Logging UI, or via the gcloud command-line tool.

To view logs with the gcloud tool, use the logs read command:

gcloud beta functions logs read

To view the logs for a specific function, provide the function name as an argument:

gcloud beta functions logs read <FUNCTION_NAME>

You can even view the logs for a specific execution:

gcloud beta functions logs read <FUNCTION_NAME> --execution-id d3w-fPZQp9KC-0

For the full range of log viewing options, view the help for logs read:

gcloud beta functions logs read -h

Using the Logging dashboard

You can also view logs for Cloud Functions from the Cloud Platform Console.

Using the Logging API

Logs written by Cloud Functions can also be retrieved through the Logging API. The Google Cloud Client Library provides an idiomatic interface to the Logging API:


// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
const Logging = require('@google-cloud/logging');

function getLogEntries () {
  // Instantiates a client
  const logging = Logging();

  const options = {
    pageSize: 10,
    filter: 'resource.type="cloud_function"'

  // Retrieve the latest Cloud Function log entries
  // See https://googlecloudplatform.github.io/gcloud-node/#/docs/logging
  return logging.getEntries(options)
    .then(([entries]) => {
      entries.forEach((entry) => console.log(entry));
      return entries;

Send feedback about...

Cloud Functions Documentation