{"library":"google-cloud-appengine-logging","title":"Google Cloud App Engine Logging","description":"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.","status":"active","version":"1.9.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-appengine-logging","tags":["google-cloud","appengine","logging","gcp","cloud-logging"],"install":[{"cmd":"pip install google-cloud-appengine-logging","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.9 or higher.","package":"Python","optional":false}],"imports":[{"note":"This is the primary import for interacting with the Cloud Logging client library.","symbol":"logging","correct":"from google.cloud import logging"}],"quickstart":{"code":"import os\nimport logging\nfrom google.cloud import logging as cloud_logging\n\n# Set your Google Cloud Project ID\n# For local testing, ensure GOOGLE_APPLICATION_CREDENTIALS is set or you're logged in via `gcloud auth application-default login`\nPROJECT_ID = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-gcp-project-id')\n\n# Instantiate a Cloud Logging client\nclient = cloud_logging.Client(project=PROJECT_ID)\n\n# Connects the Cloud Logging client to the root Python logging handler\n# This will capture all logs at INFO level and higher by default\nclient.setup_logging()\n\n# Get a standard Python logger\nlogger = logging.getLogger(__name__)\n\n# Log messages using the standard Python logging module\nlogger.info('This is an informational message.')\nlogger.warning('A warning occurred in the application.')\nlogger.error('An error was encountered!')\n\ntry:\n    1 / 0\nexcept ZeroDivisionError:\n    logger.exception('Caught an exception!')\n\nprint(f'Logs sent to Google Cloud Logging for project: {PROJECT_ID}')","lang":"python","description":"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."},"warnings":[{"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.","message":"Migration 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.","severity":"breaking","affected_versions":"All versions when migrating from App Engine first-generation to second-generation runtimes."},{"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`.","message":"Logs 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Logs 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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-04T00:00:00.000Z","next_check":"2026-07-03T00:00:00.000Z"}