Registry /
gcp / google-cloud-appengine-logging
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.
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
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.fixFor 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.fixTo 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.fixImplement 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.fixWhen 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.fixTo 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.fixEnsure the `google-cloud-logging` library is installed by running `pip install google-cloud-logging`.
affects: All versions
Audit
Dependencies
PythonrequiredRequires Python 3.9 or higher.