Enabling and authorizing the Cloud Logging API v2 lets you programmatically
read, write, and manage log entries and Cloud Logging configurations. Before
you can call the Logging API or use the Logging client
libraries, you must enable the API for your project and grant users the
required permissions.

## Enable the API

The Logging API must be enabled before it can be used. You can check
the status of the API and, if necessary, enable it by using either the
Google Cloud console or Google Cloud CLI.

### Google Cloud console

1. Go to the Logging API library page in the
   Google Cloud console:

   [Go to the **Library** page](https://console.cloud.google.com/apis/library/logging.googleapis.com)
2. Select your project.

3. The Logging API is enabled if you see a **Manage** button on
   the library page. If you see an **Enable** button, the API isn't
   enabled, and you must click the **Enable** button to enable it.

### gcloud CLI

1. If you haven't already installed the Google Cloud CLI on your
   workstation, see
   [Installing the gcloud CLI](https://docs.cloud.google.com/sdk/docs/install).

2. To see if the Logging API is enabled, run the following
   command on your workstation, after replacing <var translate="no">PROJECT_ID</var> with the
   ID of the project for which you want to enable the API:

       gcloud services list --project=PROJECT_ID

   If `logging.googleapis.com` appears in the output, the API is
   enabled.
3. If the API isn't enabled, then run the following command to enable it:

       gcloud services enable logging --project=PROJECT_ID

   For more information about managing APIs with gcloud CLI, see
   [`gcloud services`](https://docs.cloud.google.com/sdk/gcloud/reference/services).

## Authorize use of the API

Before you can use the Cloud Logging API, you must authorize users to access it.

Access to the API is controlled by Identity and Access Management (IAM) roles and
permissions. There is a permission associated with each method, and
permissions for related methods are clustered into roles, which can then
be granted to users. For more information, see
[Access control with IAM](https://docs.cloud.google.com/logging/docs/access-control.md.txt).

After access to the API is authorized, the API can be used from anywhere.
For example, you can use the [entries.list](https://docs.cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list.md.txt)
method from your local workstation to read log data from your Google Cloud
resources.

The recommended [Logging client libraries](https://docs.cloud.google.com/logging/docs/reference/libraries.md.txt) use
[Application Default Credentials](https://docs.cloud.google.com/docs/authentication/application-default-credentials.md.txt) to automatically
find credentials. For more information, see
[Authenticate for using client libraries](https://docs.cloud.google.com/docs/authentication/client-libraries.md.txt).

You can find out more about authentication for Cloud
APIs in the [Cloud authentication documentation](https://docs.cloud.google.com/docs/authentication.md.txt).

## Use client libraries

After you've enabled and authorized the use of the API, you're ready
to start writing code. To get started using the Logging client
libraries, see [Logging client libraries](https://docs.cloud.google.com/logging/docs/reference/libraries.md.txt).