Enable the Logging API

This page describes how to enable and authorize use of the Logging API v2.

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 the API if necessary by using either the Google Cloud console or Google Cloud CLI.

Google Cloud console

  1. In the Google Cloud console, select the Google Cloud project for which you want to enable the API, and then go to the APIs & Services page:

    Go to APIs & Services

  2. Click the Enable APIs and Services button.

  3. Search for "Logging".

  4. In the search results, click Cloud Logging API.

  5. If "API enabled" is displayed, then the API is already enabled. If not, then click Enable.

gcloud CLI

  1. If you haven't already installed the Google Cloud CLI on your workstation, see Installing the gcloud CLI.

  2. To see if the Logging API is enabled, run the following command on your workstation, after replacing PROJECT_ID 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 listing, enabling, and disabling APIs, see gcloud 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.

After access to the API is authorized, the API can be used from anywhere. For example, you can use the entries.list method from your local workstation to read log data from your Google Cloud resources.

If you're writing an application that uses the Logging API, the recommended Logging client libraries authorize your application using Application Default Credentials. This hides authorization details from your application code.

You can find out more about authentication and authorization for Cloud APIs in the Authentication guide.

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.