Install & Compatibility
Where this runs
tested against v0.11.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 48.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 5.3s · import 0.000s · 47MB
46MB installed
● package 46MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
logging
✓ from google import logging
✗ from google.cloud import logging
This quickstart demonstrates how to use the recommended `google-cloud-logging` library to send logs to Google Cloud Logging, integrating with Python's standard `logging` module. The `setup_logging()` method automatically configures a handler, often routing structured JSON to stdout/stderr in Cloud environments for efficient ingestion. For direct interaction with the low-level `grpc-google-logging-v2` library, the process would be significantly more complex, involving manual gRPC channel management and protobuf message construction.
import logging
import os
from google.cloud import logging as cloud_logging
# Instantiates a client for the higher-level google-cloud-logging library
client = cloud_logging.Client()
# This method sets up a handler on the root logger, routing all logs at
# INFO level and higher to Cloud Logging.
# It automatically detects the environment (e.g., Cloud Run, GKE) to
# use the most efficient logging method (e.g., structured JSON to stdout).
client.setup_logging()
# Use the standard Python logging library
logging.info("Hello from a Python standard logger!")
logging.warning("This is a warning log message.")
logging.error("An error occurred here!")
# To send structured data, log a dictionary or JSON-parsable string
# The `extra` argument can also be used for structured fields
logging.info(
"Structured log message",
extra={
"json_fields": {
"component": "my-app",
"requestId": os.environ.get('REQUEST_ID', 'N/A'),
"status": "success",
"latency_ms": 123
}
}
)
print("Logs sent to Google Cloud Logging via standard Python logging.")
# In local development, you'll see these logs in your console.
# In a Google Cloud environment (e.g., Cloud Run, GKE), they will be
# automatically ingested by Cloud Logging.
Debug
Known issues
breakingThis library is marked with an "Inactive" development status (7 - Inactive) on PyPI, and its last release was in September 2016. It is no longer actively maintained.fixMigrate to the `google-cloud-logging` library, which is actively maintained and recommended for all new and existing projects.
affects: <=0.11.1
gotchaApplication developers should almost always use the `google-cloud-logging` Python library (`pip install google-cloud-logging`) for interacting with Google Cloud Logging, not `grpc-google-logging-v2`. `google-cloud-logging` provides a user-friendly, idiomatic Python interface that integrates seamlessly with the standard `logging` module and handles the underlying gRPC communication.fixInstall and use `google-cloud-logging` (e.g., `pip install google-cloud-logging`) and refer to its official documentation for usage patterns.
affects: *
breakingThe last release of `grpc-google-logging-v2` officially supported Python 2.7, 3.4, and 3.5. Using it directly with modern Python versions (3.6+) may lead to compatibility issues or unexpected behavior due to lack of maintenance.fixUpgrade to the `google-cloud-logging` library, which supports modern Python versions.
affects: >=0.11.1 (when used with Python 3.6+)
gotcha`grpc-google-logging-v2` is a low-level, generated gRPC client. Direct usage requires deep understanding of gRPC, Protocol Buffers (especially `google.logging.v2.logging_pb2` and `logging_pb2_grpc`), and manual client stub management, which is significantly more complex than using `google-cloud-logging`.fixUtilize the higher-level abstractions provided by the `google-cloud-logging` library, which handles these complexities internally.
affects: *
gotchaWhen not using `google-cloud-logging`'s `setup_logging()` for integration, standard Python `logging.info()` calls might appear with incorrect (e.g., `ERROR`) severity in Cloud Logging, as the default behavior for raw stdout/stderr ingestion might not correctly map Python logging levels.fixAlways use `google.cloud.logging.Client().setup_logging()` when integrating the Python standard `logging` module with Google Cloud Logging via the `google-cloud-logging` library. This ensures correct severity mapping and structured logging.
affects: *
Upgrade
Version history
0.11.1latest on PyPI · released Sep 30, 2016
Audit
Dependencies
grpciorequiredCore gRPC library.
googleapis-common-protosrequiredCommon protobuf definitions for Google APIs.