Name | inuits-python-logging-loki JSON |
Version |
1.4.1
JSON |
| download |
home_page | None |
Summary | Python logging handler for Grafana Loki. |
upload_time | 2024-05-08 14:44:49 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | MIT License Copyright (c) 2019 Andrey Maslov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
inuits-python-logging-loki
inuits_python_logging_loki
python-logging-loki
python_logging_loki
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# python-logging-loki
[![PyPI version](https://img.shields.io/pypi/v/inuits-python-logging-loki.svg)](https://pypi.org/project/inuits-python-logging-loki/)
[![Python version](https://img.shields.io/badge/python-3.6%20%7C%203.8%20%7C%203.7%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue.svg)](https://www.python.org/)
[![License](https://img.shields.io/pypi/l/python-logging-loki.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.org/GreyZmeem/python-logging-loki.svg?branch=master)](https://travis-ci.org/GreyZmeem/python-logging-loki)
Python logging handler for Loki.
https://grafana.com/loki
# Installation
```bash
pip install inuits-python-logging-loki
```
# Usage
```python
import logging
import logging_loki
handler = logging_loki.LokiHandler(
url="https://my-loki-instance/loki/api/v1/push",
tags={"application": "my-app"},
headers={"X-Scope-OrgID": "example-id"},
auth=("username", "password"),
props_to_labels = ["foo"]
)
logger = logging.getLogger("my-logger")
logger.addHandler(handler)
logger.error(
"Something happened",
extra={"tags": {"service": "my-service"}},
)
```
Example above will send `Something happened` message along with these labels:
- Default labels from handler
- Message level as `serverity`
- Logger's name as `logger`
- Labels from `tags` item of `extra` dict
- Property `foo` from log record will be sent as loki label
## Properties to label
Using a dict instead of a list for `props_to_labels` will enable renaming labels
```python
handler = logging_loki.LokiHandler(
url="https://my-loki-instance/loki/api/v1/push",
tags={"application": "my-app"},
props_to_labels = {
"otelTraceID": "trace_id"
"otelSpanID": "span_id"
}
)
```
In this case, the properties `otelTraceID` & `otelSpanID` will be renamed to `trace_id` & `span_id` loki labels
## Non-blocking mode
The given example is blocking (i.e. each call will wait for the message to be sent).
But you can use the built-in `QueueHandler` and` QueueListener` to send messages in a separate thread.
```python
import logging.handlers
import logging_loki
from multiprocessing import Queue
queue = Queue(-1)
handler = logging.handlers.QueueHandler(queue)
handler_loki = logging_loki.LokiHandler(
url="https://my-loki-instance/loki/api/v1/push",
tags={"application": "my-app"},
headers={"X-Scope-OrgID": "example-id"},
auth=("username", "password"),
props_to_labels: Optional[list[str]] = ["foo"]
)
logging.handlers.QueueListener(queue, handler_loki)
logger = logging.getLogger("my-logger")
logger.addHandler(handler)
logger.error(...)
```
Or you can use `LokiQueueHandler` shortcut, which will automatically create listener and handler.
```python
import logging.handlers
import logging_loki
from multiprocessing import Queue
handler = logging_loki.LokiQueueHandler(
Queue(-1),
url="https://my-loki-instance/loki/api/v1/push",
tags={"application": "my-app"},
auth=("username", "password"),
)
logger = logging.getLogger("my-logger")
logger.addHandler(handler)
logger.error(...)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "inuits-python-logging-loki",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "inuits-python-logging-loki, inuits_python_logging_loki, python-logging-loki, python_logging_loki",
"author": null,
"author_email": "Inuits <developers@inuits.eu>, Andrey Maslov <greyzmeem@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/00/1b/d1b56f74dc9991b2f8872e61d33cef81b75db17a22525bb24734dec4c2d9/inuits_python_logging_loki-1.4.1.tar.gz",
"platform": null,
"description": "# python-logging-loki\n\n[![PyPI version](https://img.shields.io/pypi/v/inuits-python-logging-loki.svg)](https://pypi.org/project/inuits-python-logging-loki/)\n[![Python version](https://img.shields.io/badge/python-3.6%20%7C%203.8%20%7C%203.7%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue.svg)](https://www.python.org/)\n[![License](https://img.shields.io/pypi/l/python-logging-loki.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://travis-ci.org/GreyZmeem/python-logging-loki.svg?branch=master)](https://travis-ci.org/GreyZmeem/python-logging-loki)\n\nPython logging handler for Loki. \nhttps://grafana.com/loki\n\n# Installation\n\n```bash\npip install inuits-python-logging-loki\n```\n\n# Usage\n\n```python\nimport logging\nimport logging_loki\n\n\nhandler = logging_loki.LokiHandler(\n url=\"https://my-loki-instance/loki/api/v1/push\",\n tags={\"application\": \"my-app\"},\n headers={\"X-Scope-OrgID\": \"example-id\"},\n auth=(\"username\", \"password\"),\n props_to_labels = [\"foo\"]\n)\n\nlogger = logging.getLogger(\"my-logger\")\nlogger.addHandler(handler)\nlogger.error(\n \"Something happened\",\n extra={\"tags\": {\"service\": \"my-service\"}},\n)\n```\n\nExample above will send `Something happened` message along with these labels:\n\n- Default labels from handler\n- Message level as `serverity`\n- Logger's name as `logger`\n- Labels from `tags` item of `extra` dict\n- Property `foo` from log record will be sent as loki label\n\n## Properties to label\n\nUsing a dict instead of a list for `props_to_labels` will enable renaming labels\n\n```python\nhandler = logging_loki.LokiHandler(\n url=\"https://my-loki-instance/loki/api/v1/push\",\n tags={\"application\": \"my-app\"},\n props_to_labels = {\n \"otelTraceID\": \"trace_id\"\n \"otelSpanID\": \"span_id\"\n }\n)\n```\n\nIn this case, the properties `otelTraceID` & `otelSpanID` will be renamed to `trace_id` & `span_id` loki labels\n\n## Non-blocking mode\n\nThe given example is blocking (i.e. each call will wait for the message to be sent). \nBut you can use the built-in `QueueHandler` and` QueueListener` to send messages in a separate thread.\n\n```python\nimport logging.handlers\nimport logging_loki\nfrom multiprocessing import Queue\n\n\nqueue = Queue(-1)\nhandler = logging.handlers.QueueHandler(queue)\nhandler_loki = logging_loki.LokiHandler(\n url=\"https://my-loki-instance/loki/api/v1/push\",\n tags={\"application\": \"my-app\"},\n headers={\"X-Scope-OrgID\": \"example-id\"},\n auth=(\"username\", \"password\"),\n props_to_labels: Optional[list[str]] = [\"foo\"]\n)\nlogging.handlers.QueueListener(queue, handler_loki)\n\nlogger = logging.getLogger(\"my-logger\")\nlogger.addHandler(handler)\nlogger.error(...)\n```\n\nOr you can use `LokiQueueHandler` shortcut, which will automatically create listener and handler.\n\n```python\nimport logging.handlers\nimport logging_loki\nfrom multiprocessing import Queue\n\n\nhandler = logging_loki.LokiQueueHandler(\n Queue(-1),\n url=\"https://my-loki-instance/loki/api/v1/push\",\n tags={\"application\": \"my-app\"},\n auth=(\"username\", \"password\"),\n)\n\nlogger = logging.getLogger(\"my-logger\")\nlogger.addHandler(handler)\nlogger.error(...)\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2019 Andrey Maslov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Python logging handler for Grafana Loki.",
"version": "1.4.1",
"project_urls": {
"Homepage": "https://github.com/inuits/python-logging-loki"
},
"split_keywords": [
"inuits-python-logging-loki",
" inuits_python_logging_loki",
" python-logging-loki",
" python_logging_loki"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "846eac96c13704a94b5aa738ecba60424d880d24d130a9480cd227773b71cf84",
"md5": "3d990ed4bb28bf020e396f87cecc7019",
"sha256": "34d8bd04423722f049a6b39331b8c17fcacc7a9ad2b1d35f85066fd0ad249838"
},
"downloads": -1,
"filename": "inuits_python_logging_loki-1.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3d990ed4bb28bf020e396f87cecc7019",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 11649,
"upload_time": "2024-05-08T14:44:48",
"upload_time_iso_8601": "2024-05-08T14:44:48.221839Z",
"url": "https://files.pythonhosted.org/packages/84/6e/ac96c13704a94b5aa738ecba60424d880d24d130a9480cd227773b71cf84/inuits_python_logging_loki-1.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "001bd1b56f74dc9991b2f8872e61d33cef81b75db17a22525bb24734dec4c2d9",
"md5": "3ed79930b4916bb4005138e76bc4c1b0",
"sha256": "b880935ce875ee71c577e1d81faaa6501e6b26bcdbf6d6bb1d99bf4264a61b8c"
},
"downloads": -1,
"filename": "inuits_python_logging_loki-1.4.1.tar.gz",
"has_sig": false,
"md5_digest": "3ed79930b4916bb4005138e76bc4c1b0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10177,
"upload_time": "2024-05-08T14:44:49",
"upload_time_iso_8601": "2024-05-08T14:44:49.837867Z",
"url": "https://files.pythonhosted.org/packages/00/1b/d1b56f74dc9991b2f8872e61d33cef81b75db17a22525bb24734dec4c2d9/inuits_python_logging_loki-1.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-08 14:44:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "inuits",
"github_project": "python-logging-loki",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "inuits-python-logging-loki"
}