Name | gcp-log JSON |
Version |
1.0.1
JSON |
| download |
home_page | None |
Summary | Format logs as GCP-compatible JSON. |
upload_time | 2023-08-31 11:18:05 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
gcp
google
logging
logger
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# gcp-log
Python library to format logs as [GCP](https://cloud.google.com/)-compatible JSON.
Features:
+ Works with standard [logging](https://docs.python.org/3/library/logging.html).
+ Supports [extra](https://docs.python.org/3/library/logging.html#logging.Logger.debug) for structured logging.
+ 100% compatible with [the official spec](https://cloud.google.com/logging/docs/structured-logging#special-payload-fields).
+ 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](https://pypi.org/project/orjson/) for better performance.
## Installation
```shell
python3 -m pip install gcp-log
```
**Optional:** If you also install [orjson](https://pypi.org/project/orjson/), gcp-log will automatically use it instead of stdlib [json](https://docs.python.org/3/library/json.html) for faster serialization:
```shell
python3 -m pip install orjson
```
## Usage
To use it, simply set `gcp_log.Formatter` as the [formatter](https://docs.python.org/3/library/logging.html#formatter-objects) for the logger:
```python
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:
```python
logger.info('aragorn', extra=dict(father='arathorn'))
```
The output:
```json
{"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:
```json
{
"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",
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "gcp-log",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "gcp,google,logging,logger",
"author": null,
"author_email": "Gram <git@orsinium.dev>",
"download_url": "https://files.pythonhosted.org/packages/81/47/ce9947128526299723a1766e6a70c440357338ee9e577d07610b2305734a/gcp_log-1.0.1.tar.gz",
"platform": null,
"description": "# gcp-log\n\nPython library to format logs as [GCP](https://cloud.google.com/)-compatible JSON.\n\nFeatures:\n\n+ Works with standard [logging](https://docs.python.org/3/library/logging.html).\n+ Supports [extra](https://docs.python.org/3/library/logging.html#logging.Logger.debug) for structured logging.\n+ 100% compatible with [the official spec](https://cloud.google.com/logging/docs/structured-logging#special-payload-fields).\n+ Non-invasive, doesn't start any threads or processes, doesn't make network or system calls.\n+ Zero configuration.\n+ Fast.\n+ Pure Python.\n+ Type-safe.\n+ Zero dependency.\n+ Optional integration with [orjson](https://pypi.org/project/orjson/) for better performance.\n\n## Installation\n\n```shell\npython3 -m pip install gcp-log\n```\n\n**Optional:** If you also install [orjson](https://pypi.org/project/orjson/), gcp-log will automatically use it instead of stdlib [json](https://docs.python.org/3/library/json.html) for faster serialization:\n\n```shell\npython3 -m pip install orjson\n```\n\n## Usage\n\nTo use it, simply set `gcp_log.Formatter` as the [formatter](https://docs.python.org/3/library/logging.html#formatter-objects) for the logger:\n\n```python\nimport logging\nimport gcp_log\n\nlogger = logging.getLogger()\nhandler = logging.StreamHandler()\nformatter = gcp_log.Formatter()\nhandler.setFormatter(formatter)\nlogger.addHandler(handler)\n```\n\nAnd then you can use the logger:\n\n```python\nlogger.info('aragorn', extra=dict(father='arathorn'))\n```\n\nThe output:\n\n```json\n{\"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\"}\n```\n\nA human-readable version:\n\n```json\n{\n \"message\": \"aragorn\",\n \"severity\": \"INFO\",\n \"timestamp\": \"2022-03-17T10:09:58.393124+00:00Z\",\n \"logging.googleapis.com/sourceLocation\": {\n \"file\": \"/full/path/to/example.py.py\",\n \"line\": 24,\n \"function\": \"test_gcp_formatter\",\n },\n \"father\": \"arathorn\",\n}\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Format logs as GCP-compatible JSON.",
"version": "1.0.1",
"project_urls": {
"Source": "https://github.com/orsinium-labs/gcp-log"
},
"split_keywords": [
"gcp",
"google",
"logging",
"logger"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "bf9310bd9ea717a69728d74f0c34e1baff238d4cee6b3a2bc39b458ec53527bf",
"md5": "9a7e23016c1395a6fb9423185f39cb94",
"sha256": "90a7f7108d20816761454823f27d4c051f09da6eda30cc5e84b11c9686bfbbf4"
},
"downloads": -1,
"filename": "gcp_log-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9a7e23016c1395a6fb9423185f39cb94",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4426,
"upload_time": "2023-08-31T11:18:02",
"upload_time_iso_8601": "2023-08-31T11:18:02.566684Z",
"url": "https://files.pythonhosted.org/packages/bf/93/10bd9ea717a69728d74f0c34e1baff238d4cee6b3a2bc39b458ec53527bf/gcp_log-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "8147ce9947128526299723a1766e6a70c440357338ee9e577d07610b2305734a",
"md5": "c6c93b4a6562267f1c244266606724f6",
"sha256": "798a7d8e457a6db12437b7e2b44f5824f0d3aba52b9b0c5d78d7265ccf1fee7f"
},
"downloads": -1,
"filename": "gcp_log-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "c6c93b4a6562267f1c244266606724f6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 5373,
"upload_time": "2023-08-31T11:18:05",
"upload_time_iso_8601": "2023-08-31T11:18:05.027885Z",
"url": "https://files.pythonhosted.org/packages/81/47/ce9947128526299723a1766e6a70c440357338ee9e577d07610b2305734a/gcp_log-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-31 11:18:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "orsinium-labs",
"github_project": "gcp-log",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "gcp-log"
}