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.2.1

Write entries to [Stackdriver 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 permission to the project member that will represent your extension to the Stackdriver 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 GCP 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.md.txt) the extension using the [configuration reference](https://docs.apigee.com/api-platform/reference/extensions/google-stackdriver-logging/google-stackdriver-logging-extension-121.md.txt#configuration_reference).

## About Stackdriver Logging

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

This extension currently writes entries to the log.

For more, see the [Stackdriver Logging docs](https://cloud.google.com/logging/docs/).

## Samples

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

### Global log

The following policy writes the message "This is a test" to a log called example-log in the Stackdriver 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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="true" enabled="true" name="Logging-Extension">
    <DisplayName>Logging Connector</DisplayName>
    <Connector>stackdriver-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.md.txt).

## Actions


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

<br />

### log

Writes a message to the log.

This action writes a Stackdriver 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 contents of the `metadata` property, see the [LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) object in the Stackdriver Logging documentation.

### Syntax

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

### Example: String

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

### Example: JSON

```xml
<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.md.txt).

## 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-stackdriver-logging/google-stackdriver-logging-extension-121.md.txt#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 GCP 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. |