A structlog processor for Google Cloud Run logging.
Project description
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
eventfield) - 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+
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file structlog_cloudrun-0.2.0.tar.gz.
File metadata
- Download URL: structlog_cloudrun-0.2.0.tar.gz
- Upload date:
- Size: 34.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89447158a94351db5464b183d3f0afcc640d0138621a229448a65a92a497d9f5
|
|
| MD5 |
9045c0269063762e6e1605deec5b9548
|
|
| BLAKE2b-256 |
afe610b0b6b5009d66a11664b211ede1408ea9657679c9757cc7f0c6794cb4e1
|
File details
Details for the file structlog_cloudrun-0.2.0-py3-none-any.whl.
File metadata
- Download URL: structlog_cloudrun-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c34dbf2fa1555af7755c767e69c506c84c3fdaf623be23a24ac6e44d96ad5303
|
|
| MD5 |
7678f7534c66d0e3cb63dea6844beaab
|
|
| BLAKE2b-256 |
bae5e19a0e0a0a7df9d5611cc886ab97222ec283f36bc35a7f3086b2658cf69a
|