Format logs as GCP-compatible JSON.
Project description
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",
}
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 gcp_log-1.0.1.tar.gz.
File metadata
- Download URL: gcp_log-1.0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
798a7d8e457a6db12437b7e2b44f5824f0d3aba52b9b0c5d78d7265ccf1fee7f
|
|
| MD5 |
c6c93b4a6562267f1c244266606724f6
|
|
| BLAKE2b-256 |
8147ce9947128526299723a1766e6a70c440357338ee9e577d07610b2305734a
|
File details
Details for the file gcp_log-1.0.1-py3-none-any.whl.
File metadata
- Download URL: gcp_log-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90a7f7108d20816761454823f27d4c051f09da6eda30cc5e84b11c9686bfbbf4
|
|
| MD5 |
9a7e23016c1395a6fb9423185f39cb94
|
|
| BLAKE2b-256 |
bf9310bd9ea717a69728d74f0c34e1baff238d4cee6b3a2bc39b458ec53527bf
|