Registry / gcp / google-cloud-appengine-logging

google-cloud-appengine-logging

JSON →
library1.9.0pypypi✓ verified 50d ago

The `google-cloud-appengine-logging` Python client library provides an interface to Google Cloud Logging specifically tailored for applications running on Google App Engine. It enables developers to integrate Python's standard `logging` module with Cloud Logging, facilitating the collection, storage, and analysis of application logs. The current version is 1.9.0, and being part of the `google-cloud-python` monorepo, it receives frequent updates for bug fixes and feature enhancements across various Google Cloud services.

gcpobservability
pip install google-cloud-appengine-logging
Install & Compatibility
Where this runs
tested against v1.9.0 · 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
musl
glibc
py 3.10
4/6 runs
4/6 runs
py 3.11
4/6 runs
4/6 runs
py 3.12
4/6 runs
4/6 runs
py 3.13
4/6 runs
4/6 runs
py 3.9
4/6 runs
4/6 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

logging
from google.cloud import appengine_logging as logging
from google.cloud import logging

This quickstart demonstrates how to integrate `google-cloud-appengine-logging` with Python's standard `logging` module. It initializes the Cloud Logging client and then configures it to capture logs from the root Python logger, sending them to your specified Google Cloud project. This setup is particularly useful for App Engine applications to ensure logs are visible in Cloud Logging's Logs Explorer. Remember to replace 'your-gcp-project-id' with your actual project ID, or ensure the `GOOGLE_CLOUD_PROJECT` environment variable is set.

import os import logging from google.cloud import logging as cloud_logging # Set your Google Cloud Project ID # For local testing, ensure GOOGLE_APPLICATION_CREDENTIALS is set or you're logged in via `gcloud auth application-default login` PROJECT_ID = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-gcp-project-id') # Instantiate a Cloud Logging client client = cloud_logging.Client(project=PROJECT_ID) # Connects the Cloud Logging client to the root Python logging handler # This will capture all logs at INFO level and higher by default client.setup_logging() # Get a standard Python logger logger = logging.getLogger(__name__) # Log messages using the standard Python logging module logger.info('This is an informational message.') logger.warning('A warning occurred in the application.') logger.error('An error was encountered!') try: 1 / 0 except ZeroDivisionError: logger.exception('Caught an exception!') print(f'Logs sent to Google Cloud Logging for project: {PROJECT_ID}')
Debug
Known issues
breakingMigration from App Engine First-Generation Runtimes to Second-Generation Runtimes changes logging behavior significantly. Pre-integrated logging is not supported, and logs are no longer automatically correlated. You must explicitly use the Cloud Logging client library to achieve proper log correlation and structured logging.
fix
For second-generation runtimes, install `google-cloud-appengine-logging` and use `client.setup_logging()` or explicitly include trace IDs in your log entries to correlate app logs with request logs.
affects: All versions when migrating from App Engine first-generation to second-generation runtimes.
gotchaLogs from the `google`-level logger are not propagated to the root Python logger by default. This means if you expect logs from Google client libraries to appear in your general application log streams (e.g., stdout/stderr handlers attached to the root logger), you need to explicitly configure propagation.
fix
To ensure Google client library logs are propagated to the root logger, add `logging.getLogger("google").propagate = True` to your application's logging configuration after importing `logging`.
affects: All versions
gotchaLogs may contain sensitive information. The library itself logs RPC events that might include sensitive data. Exercise caution when collecting, storing, and accessing logs to comply with data privacy and security policies.
fix
Implement strict access controls for Cloud Logging and review the content of your logs to avoid inadvertently exposing sensitive data. Mask or redact sensitive information before it is logged.
affects: All versions
gotchaFor optimal analysis in Cloud Logging's Logs Explorer, especially when wanting parsed fields, it's recommended to log structured JSON payloads instead of plain text strings. While plain text logs are ingested, they appear in a `textPayload` field without easy field-based filtering.
fix
When using the standard Python `logging` module, implement a custom formatter that serializes your log records into JSON strings, or directly log dictionary objects to the `CloudLoggingHandler` if using it explicitly without `setup_logging`.
affects: All versions
breakingThe Cloud Logging client library cannot be imported directly as `from google.cloud import logging`. This will result in an `ImportError` because `logging` is not directly exposed as a top-level module under `google.cloud` for the client library, and it also causes a name conflict with Python's built-in `logging` module.
fix
To use the Cloud Logging client library, import the `Client` class from `google.cloud.logging` (e.g., `from google.cloud.logging import Client`) or import the v2 client as `from google.cloud import logging_v2`.
affects: All versions
breakingAn `ImportError: cannot import name 'logging' from 'google.cloud'` indicates that the `google-cloud-logging` library is not installed or accessible in your environment.
fix
Ensure the `google-cloud-logging` library is installed by running `pip install google-cloud-logging`.
affects: All versions
Upgrade
Version history
1.10.0latest on PyPI
Audit
Dependencies
PythonrequiredRequires Python 3.9 or higher.
Agent activity
80 hits · last 30 days
node
16
mj12bot
4
ahrefsbot
3
petalbot
1
amazonbot
1
seranking-bot
1
Resources