Skip to main content

structlog-cloudrun

A structlog processor for Google Cloud Run logging.

This package provides a structured logging processor that formats log entries to be compatible with Google Cloud Logging when running on Cloud Run.

Features

  • Converts structlog events to Google Cloud Logging format
  • Maps Python log levels to Cloud Logging severity levels
  • Automatic UTC timestamp generation
  • Separates log messages and structured data appropriately

Installation

Install using pip:

pip install structlog-cloudrun

Or using uv:

uv add structlog-cloudrun

Quick Start

import structlog
from structlog_cloudrun import CloudRunProcessor

# Configure structlog with CloudRunProcessor
structlog.configure(
    processors=[
        structlog.contextvars.merge_contextvars,
        structlog.processors.add_log_level,
        CloudRunProcessor(),
        structlog.processors.JSONRenderer(),
    ],
    cache_logger_on_first_use=True,
)

# Use structured logging
logger = structlog.get_logger()
logger.info("User logged in", user_id="12345", method="oauth")

This will output JSON formatted for Google Cloud Logging:

{
  "severity": "INFO",
  "timestamp": "2023-12-07T10:30:00.000000Z",
  "textPayload": "User logged in",
  "jsonPayload": {
    "user_id": "12345",
    "method": "oauth"
  }
}

Log Format

The processor converts structlog events into Google Cloud Logging's LogEntry format:

  • severity: Mapped from Python log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • timestamp: UTC timestamp in ISO format
  • textPayload: The main log message (from the event field)
  • jsonPayload: All other structured data from the log event

Severity Mapping

Python Level Cloud Logging Severity
notset DEFAULT
debug DEBUG
info INFO
notice NOTICE
warning WARNING
error ERROR
critical CRITICAL

Requirements

  • Python 3.11+
  • structlog 25.0.0+

Metadata

Release files for structlog-cloudrun 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for structlog-cloudrun 0.2.0
File Size Uploaded Provenance Actions
structlog_cloudrun-0.2.0.tar.gz 34.3 kB Without provenance Details for structlog_cloudrun-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for structlog-cloudrun 0.2.0
File Interpreter ABI Platform Actions
structlog_cloudrun-0.2.0-py3-none-any.whl Python 3 none any Details for structlog_cloudrun-0.2.0-py3-none-any.whl

Total release size: 37.9 kB

Release files / structlog_cloudrun-0.2.0.tar.gz

Download URL structlog_cloudrun-0.2.0.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
89447158a94351db5464b183d3f0afcc640d0138621a229448a65a92a497d9f5
BLAKE2b-256 checksum
How to use checksums
afe610b0b6b5009d66a11664b211ede1408ea9657679c9757cc7f0c6794cb4e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.2

Release files / structlog_cloudrun-0.2.0-py3-none-any.whl

Download URL structlog_cloudrun-0.2.0-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c34dbf2fa1555af7755c767e69c506c84c3fdaf623be23a24ac6e44d96ad5303
BLAKE2b-256 checksum
How to use checksums
bae5e19a0e0a0a7df9d5611cc886ab97222ec283f36bc35a7f3086b2658cf69a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.2

Security for structlog-cloudrun 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page