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
gcp-log-1.0.0.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file gcp-log-1.0.0.tar.gz
.
File metadata
- Download URL: gcp-log-1.0.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29336f1f0319579ed037799100800b0d3db061e82612e8cd67b9b0ae0fedd433 |
|
MD5 | 6d1b5edbb3ff6b4ebc79f125330670de |
|
BLAKE2b-256 | af029ea2af98644e1a8600c26ebf8e9b688e0e00663f5f5f81686765f62cebdf |
File details
Details for the file gcp_log-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: gcp_log-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b7ba1b5b1789a61b4eb8e99539bff114f61c4e8fa5804f832d89897c3bad982 |
|
MD5 | ddda68b60ca86e5f0f7b300ffae9f9b2 |
|
BLAKE2b-256 | e9af4b442830a71192fd0bf0e9a45ca1cad4560e5142fd259e14c6cc78bf366d |