Send logs to Cloud Logging

Workflows automatically generates execution logs for workflow executions in Cloud Logging.

You can also enable call logging. Or, you can create custom logs that use the sys.log function in your source. Call logging and custom logs let you control when logs are sent to Logging during a workflow execution and can be particularly helpful when debugging your workflow.

For details, including the engine_call and executions_system logging proto files, see this GitHub repository.

Execution logs

Each workflow execution automatically triggers at least two execution logs: one at the start of an execution and one at the end.

For more information about the Workflows platform logs that are available in Logging, see Google Cloud platform logs.

Call logging

You can set a flag so that each call step during the execution of your workflow is logged, and step names, function names, function arguments, and call responses are returned. Or, you can log any exceptions that stop a call.

Only explicit call steps are logged; for example, calls to subworkflows or library functions. Calls from within expressions, or within standard library functions (for example, http.post in sys.log), and inside connectors are not logged.

You can apply call logging using either the Google Cloud Console or the gcloud command-line tool.

Console

  1. Go to the Workflows page in the Google Cloud Console:
    Go to Workflows

  2. On the Workflows page, select a workflow to go to its details page.

  3. On the Workflow Details page, click Execute.

  4. Optionally, on the Execute workflow page, you can specify the level of call logging that you want to apply during the execution of the workflow.

    In the Log calls drop-down list, select one of:

    • none: No call logging. This is the default level.
    • log-all-calls: Log all calls to subworkflows or library functions and their results.
    • log-errors-only: Log only when a call is stopped due to an exception.
  5. Click Execute.

gcloud

To execute a workflow and wait for the execution to complete, enter the following command:

gcloud workflows run WORKFLOW_NAME \
    --call-log-level=CALL_LOGGING_LEVEL \
    --data=DATA

Or, to execute a workflow without waiting for the execution attempt to finish, enter the following command:

gcloud workflows execute WORKFLOW_NAME \
    --call-log-level=CALL_LOGGING_LEVEL \
    --data=DATA

Replace the following:

  • WORKFLOW_NAME: the name of the workflow.
  • CALL_LOGGING_LEVEL: optional. Level of call logging to apply during execution. Can be one of:
    • none: No call logging. This is the default level.
    • log-all-calls: Log all calls to subworkflows or library functions and their results.
    • log-errors-only: Log only when a call is stopped due to an exception.
  • DATA: optional. Runtime arguments for your workflow in JSON format.

Custom logs

To create a log entry in Logging during a workflow execution, define a step in the workflow that makes a call to the standard library sys.log function:

YAML

  - step1:
      assign:
          - varA: "Hello"
          - varB: "World"
  - logStep:
      call: sys.log
      args:
          text: TEXT
          severity: SEVERITY 
  - step2:
      return: ${varA + " " + varB}
    

JSON

    [
      {
        "step1": {
          "assign": [
            {
              "varA": "Hello"
            },
            {
              "varB": "World"
            }
          ]
        }
      },
      {
        "logStep": {
          "call": "sys.log",
          "args": {
            "text": "TEXT",
            "severity": "SEVERITY"
          }
        }
      },
      {
        "step2": {
          "return": "${varA + " " + varB}"
        }
      }
    ]
      

When creating a log entry, define the following:

  • TEXT: required. The text to be logged. If you need to log the values of a map, use ${json.encode_to_string(myMap)}.
  • SEVERITY: optional. The severity level of the log entry. For example, INFO, WARNING, or CRITICAL.

For more information, see the sys.log function reference.

Required permissions

To apply call logging or send custom logs to Logging, a workflow must be associated with a service account that includes the logging.logEntries.create permission (for example, the roles/logging.logWriter role). If you need to change the service account updated with your workflow, see Update a workflow. To learn more about creating service accounts and assigning roles, see Manage access to projects, folders, and organizations.

View workflow logs

You can view logs in Workflows or in Logging. To view the logs for a single workflow, use the Logs tab in Workflows. To get an aggregate view of the logs for all of your workflows, use the Logs Explorer page in Logging.

View logs in Workflows

To view a workflow's logs in Workflows, do the following:

  1. Go to the Workflows page in the Cloud Console:
    Go to Workflows

  2. To access a workflow's logs, click the workflow's name to go to its Details page.

  3. To view the logs, click Logs.

  4. To filter the logs by severity, in the Default list, select the type of log to display. By default, logs of all severity levels are shown.

The Logs tab on a workflow's Details page displays the following types of logs:

  • Logs sent to Logging

  • Audit logs of any operations performed on the workflow, such as updates to the workflow's definition

View logs in Logging

To view logs in Logging, do the following:

  1. Go to the Logs Explorer page in the Cloud Console:
    Go to Logs Explorer

  2. In the Query builder, click Resource and enter workflow. Select Cloud Workflow from the list and click Add.

    Workflow logging

  3. Click Run query.

To learn more about viewing logs in Logging, see Use the Logs Explorer.

What's next