Skip to main content

gcp-log

Python library to format logs as GCP-compatible JSON.

Features:

  • Works with standard logging.
  • Supports extra for structured logging.
  • 100% compatible with the official spec.
  • Non-invasive, doesn't start any threads or processes, doesn't make network or system calls.
  • Zero configuration.
  • Fast.
  • Pure Python.
  • Type-safe.
  • Zero dependency.
  • Optional integration with orjson for better performance.

Installation

python3 -m pip install gcp-log

Optional: If you also install orjson, gcp-log will automatically use it instead of stdlib json for faster serialization:

python3 -m pip install orjson

Usage

To use it, simply set gcp_log.Formatter as the formatter for the logger:

import logging
import gcp_log

logger = logging.getLogger()
handler = logging.StreamHandler()
formatter = gcp_log.Formatter()
handler.setFormatter(formatter)
logger.addHandler(handler)

And then you can use the logger:

logger.info('aragorn', extra=dict(father='arathorn'))

The output:

{"message":"aragorn","severity":"INFO","timestamp":"2022-03-17T10:09:58.393124+00:00Z","logging.googleapis.com/sourceLocation":{"file":"/full/path/to/example.py.py","line":24,"function":"test_gcp_formatter"},"father":"arathorn"}

A human-readable version:

{
    "message": "aragorn",
    "severity": "INFO",
    "timestamp": "2022-03-17T10:09:58.393124+00:00Z",
    "logging.googleapis.com/sourceLocation": {
        "file": "/full/path/to/example.py.py",
        "line": 24,
        "function": "test_gcp_formatter",
    },
    "father": "arathorn",
}

Release files for gcp-log 1.0.1

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

Source distribution (sdist)

Source distribution for gcp-log 1.0.1
File Size Uploaded
gcp_log-1.0.1.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gcp-log 1.0.1
File Interpreter ABI Platform
gcp_log-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / gcp_log-1.0.1.tar.gz

Download URL gcp_log-1.0.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
798a7d8e457a6db12437b7e2b44f5824f0d3aba52b9b0c5d78d7265ccf1fee7f
BLAKE2b-256 checksum
How to use checksums
8147ce9947128526299723a1766e6a70c440357338ee9e577d07610b2305734a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / gcp_log-1.0.1-py3-none-any.whl

Download URL gcp_log-1.0.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90a7f7108d20816761454823f27d4c051f09da6eda30cc5e84b11c9686bfbbf4
BLAKE2b-256 checksum
How to use checksums
bf9310bd9ea717a69728d74f0c34e1baff238d4cee6b3a2bc39b458ec53527bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

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