You're viewing **Apigee Edge** documentation.  
[Go to the
**Apigee X** documentation](http://cloud.google.com/apigee/docs). info

<br />


> [!NOTE]
> **Note:** Apigee Extensions are available in the Edge UI to Google Cloud Apigee customers with an Enterprise [support](https://cloud.google.com/apigee/pricing) plan.

> [!NOTE]
> **Note:** Extensions marked as deprecated will no longer be available for selection by users. However, the currently deployed version(s) will remain unaffected.

> [!CAUTION]
> **Caution:** This version of the extension is no longer supported and has been deprecated.

<br />

> Version 1.6.1

> [!NOTE]
> **Note:** Stackdriver logging is now [Cloud logging](https://cloud.google.com/products/operations)

Write entries to [Cloud Logging](https://cloud.google.com/logging/) logs.

This content provides reference for configuring and using this extension.

## Prerequisites

Before using this extension from an API proxy, you must:

1. In IAM, assign the **Logging \> Logs Writer** role to the project member that will represent your extension to the Cloud Logging system. For instructions on how to grant roles, see [Granting roles to a service account for specific resources](https://cloud.google.com/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource).
   For more on logging roles, see [Access Control Guide](https://cloud.google.com/logging/docs/access-control).

2. [Use the Google Cloud Console to generate a key for the service account](https://cloud.google.com/iam/docs/creating-managing-service-account-keys).

3. Use the contents of the resulting key JSON file when [adding and configuring](https://docs.apigee.com/api-platform/extensions/configuring-an-extension) the extension using the [configuration reference](https://docs.apigee.com/api-platform/reference/extensions/google-cloud-logging/google-cloud-logging-extension-161#configuration_reference).

This extension supports being called by an [ExtensionCallout policy](https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy) located in [PostClientFlow](https://docs.apigee.com/api-platform/fundamentals/what-are-flows#designingflowexecutionsequence-havingcodeexecuteaftertheclientreceivesyourproxysresponsewithapostclientflow).
If you want to use the [ExtensionCallout policy](https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy) to call this extension from a
PostClientFlow, ensure that the `features.allowExtensionsInPostClientFlow` flag
is set to `true` in your organization.

- If you are an Apigee Edge for Public Cloud customer, you must contact [Apigee Edge Support](https://docs.apigee.com/api-platform/troubleshoot/support) to ensure that the
  `features.allowExtensionsInPostClientFlow` flag is set to `true` in your organization.

- If you are an Apigee Edge for Private Cloud customer, use the
  [Update organization properties](https://apidocs.apigee.com/docs/organizations/1/routes/organizations/%7Borg_name%7D/post%22) API
  to set the `features.allowExtensionsInPostClientFlow` flag to `true`.

> [!NOTE]
> **Note:** The health-check to verify if the credentials have the right permissions is done through `dry-run` of a log write to `testLog` with a message of `testMsg`.

## About Cloud Logging

> [!NOTE]
> **Note:** Stackdriver logging is now [Cloud logging](https://cloud.google.com/products/operations)

[Cloud Logging](https://cloud.google.com/logging/) is part of the Google Cloud's
operations suite. It includes storage for logs, a user interface called the Logs
explorer, and an API to manage logs programmatically. With Cloud Logging, you can
read and write log entries, search and filter your logs, export your logs, and
create logs-based metrics.

The Cloud Logging extension currently writes entries to the log. For more,
see the [Cloud Logging docs](https://cloud.google.com/logging/docs/).

## Samples

The following examples illustrate how to configure support for Cloud Logging
extension actions using the [ExtensionCallout policy](https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy).

### Global log

The following policy writes the message `This is a test` to a log called
`example-log` in the Cloud Global resource. In actual use, you'd probably
have the message be contained in a flow variable whose value you set elsewhere
in the API proxy.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ConnectorCallout async="false" continueOnError="true" enabled="true" name="Logging-Extension">
        <DisplayName>Logging Connector</DisplayName>
        <Connector>cloud-extension-sample</Connector>
        <Action>log</Action>
        <Input><![CDATA[{
            "logName": "example-log",
            "metadata": {
                "resource": {
                    "type": "global",
                    "labels": {
                        "project_id": "my-test"
                    }
                }
            },
            "message": "This is a test."
        }]]></Input>
    </ConnectorCallout>

This content provides reference for configuring and using this extension.
For steps to configure an extension using the Apigee console, see
[Adding and configuring an extension](https://docs.apigee.com/api-platform/extensions/configuring-an-extension).

## Actions


> [!NOTE]
> **Note:** See the [ExtensionCallout policy](https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy) for more information on setting [`<Action>`](https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy#action_element), [`<Input>`](https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy#input_element), and [`<Output>`](https://docs.apigee.com/api-platform/reference/policies/extension-callout-policy#output_element).

<br />

### log

Writes a message to the log.

This action writes a Cloud Logging log entry. Log entries consist of metadata
and the entry data. For more about log entries, see the
[Entry reference](https://cloud.google.com/nodejs/docs/reference/logging/1.2.x/Entry).
For information about the contents of the `metadata` property, see the
[LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry)
object in the Cloud Logging documentation.

### Syntax

    <Action>log</Action>
    <Input><![CDATA[{
      "logName" : "cloud-log-name-to-use",
      "metadata" : JSON-structured-metadata,
      "message" : "data-to-log-as-entry"
    }]]></Input>

### Example: String

    <Action>log</Action>
    <Input><![CDATA[{
      "logName" : "example-log",
      "metadata" : { "resource" : { "type" : "global" } },
      "message": "This is a test."
    }]]></Input>

### Example: JSON

    <Action>log</Action>
    <Input><![CDATA[{
      "logName" : "example-log",
      "metadata" : { "resource" : { "type" : "global" } },
      "message" : { "info" :  "This is a test." }
    }]]></Input>

#### Request parameters

| Parameter | Description | Type | Default | Required |
|---|---|---|---|---|
| `logName` | The name of the log to which this entry belongs. | String | None | Yes |
| `metadata` | Metadata about the log entry. For more information and options on setting `type` and `labels` in `metadata` see [MonitoredResource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/MonitoredResource). | JSON | None | No |
| `message` | Data to use as the value for this log entry. You can specify a simple string or use JSON to log a more structured message. | String or JSON | None | Yes |

#### Response

`None` if the message was written to the log. Otherwise, the request will return an error. See also [Debugging an extension](https://docs.apigee.com/api-platform/extensions/debugging-an-extension).

## Configuration reference

Use the following when you're configuring and deploying this extension for use in API proxies.

> [!NOTE]
> **Note:** The ability to configure and deploy extensions is available only to organization administrators.

### Common extension properties

The following properties are present for every extension.

| Property | Description | Default | Required |
|---|---|---|---|
| `name` | Name you're giving this configuration of the extension. | None | Yes |
| `packageName` | Name of the extension package as given by Apigee Edge. | None | Yes |
| `version` | Version number for the extension package from which you're configuring an extension. | None | Yes |
| `configuration` | Configuration value specific to the extension you're adding. See [Properties for this extension package](https://docs.apigee.com/api-platform/reference/extensions/google-cloud-logging/google-cloud-logging-extension-161#properties_for_this_extension_package) | None | Yes |

### Properties for this extension package

Specify values for the following configuration properties specific to this extension.

| Property | Description | Default | Required |
|---|---|---|---|
| `projectId` | The Google Cloud project ID where logs should be created. | None | Yes |
| `credentials` | When entered in the Apigee Edge console, this is the contents of your service account key file. When sent via the management API, it is a base64-encoded value generated from the service account key file. | None | Yes |