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",
}
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gcp_log-1.0.1.tar.gz | 5.4 kB | Without provenance | Details for gcp_log-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gcp_log-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for gcp_log-1.0.1-py3-none-any.whl |
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
|
Security for gcp-log 1.0.1
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.