A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/logging/docs/setup/python below:

Setting Up Cloud Logging for Python

Setting Up Cloud Logging for Python

Stay organized with collections Save and categorize content based on your preferences.

You can write logs to Cloud Logging from Python applications by using the standard Python logging handler, or by using the Cloud Logging API client library for Python directly. When you use the standard Python logging handler, you must attach a Cloud Logging handler to the Python root handler. This document illustrates that approach.

Before you begin
  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Cloud Logging API.

    Enable the API

  5. Prepare your environment for Python development.

    Go to the Python setup guide

Install the library

To install the Cloud Logging library for Python, see Install the client library for Python. This library lets you attach a Cloud Logging handler to the standard Python root handler. You can also use this library to send API requests to Cloud Logging.

For more information on installation, see the documentation for the Cloud Logging library for Python. You can also report issues using the issue tracker.

Write logs with the standard Python logging handler

To send all log entries that are written with the standard Python root handler to Cloud Logging, do the following:

  1. Attach the Cloud Logging handler to the Python root logger by calling the setup_logging method:

    For information about how to configure the logging handler, see Integration with logging Standard Library.

    For information about the parameters to the setup_logging function, go to the Cloud Logging Client and search for setup_logging. This page, for example, describes how to configure logging levels.

  2. Write log data by using the Python root logger:

    By default, any log whose severity level is at least INFO that is written by your application is sent to Cloud Logging.

    If messages are logged to Logging from App Engine or Google Kubernetes Engine, then the handler sends them to those environments' respective resource types; otherwise, logs are listed under the python log in the Global resource type.

Write logs with the Cloud Logging client library

For information on using the Cloud Logging client library for Python directly, see Cloud Logging Client Libraries.

Run on Google Cloud

For an application to write logs by using the Cloud Logging library for Python, the service account for the underlying resource must have the Logs Writer (roles/logging.logWriter) IAM role. Most Google Cloud environments automatically configure the default service account to have this role.

App Engine

Cloud Logging is automatically enabled for App Engine, and your app's default service account has the IAM permissions by default to write log entries.

For more information, see Writing and viewing logs.

Google Kubernetes Engine (GKE)

GKE automatically grants the default service account the Logs Writer (roles/logging.logWriter) IAM role. If you use Workload Identity Federation for GKE with this default service account to let workloads access specific Google Cloud APIs, then no additional configuration is required. However, if you use Workload Identity Federation for GKE with a custom IAM service account, then ensure that the custom service account has the role of Logs Writer (roles/logging.logWriter).

If needed, you can also use the following command to add the logging.write access scope when creating the cluster:

gcloud container clusters create example-cluster-name \
    --scopes https://www.googleapis.com/auth/logging.write
Compute Engine Note: To use the Cloud Logging library for Python on a Compute Engine VM instance, you do not need to install the Cloud Logging agent.

When using Compute Engine VM instances, add the cloud-platform access scope to each instance. When creating a new instance through the Google Cloud console, you can do this in the Identity and API access section of the Create Instance panel. Use the Compute Engine default service account or another service account of your choice, and select Allow full access to all Cloud APIs in the Identity and API access section. Whichever service account you select, ensure that it has been granted the Logs Writer role in the IAM & Admin section of the Google Cloud console.

Run locally and elsewhere

To use the Cloud Logging library for Python outside of Google Cloud, including running the library on your own workstation, on your data center's computers, or on the VM instances of another cloud provider, you must set up Application Default Credentials (ADC) in your local environment to authenticate to the Cloud Logging library for Python.

For more information, see Set up ADC for on-premises or another cloud provider.

View the logs

In the Google Cloud console, go to the Logs Explorer page:

Go to Logs Explorer

If you use the search bar to find this page, then select the result whose subheading is Logging.

In the Logs Explorer, you must specify one or more resources, but the resource selection might not be obvious. Here are some tips to help you get started:

For additional information, see Using the Logs Explorer.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-11 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-11 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4