Name | logstruct JSON |
Version |
0.1
JSON |
| download |
home_page | None |
Summary | Structured stdlib logging |
upload_time | 2024-08-12 19:01:12 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | BSD-3-Clause |
keywords |
logging
structured
stdlib
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
logstruct
=========
Everything you need to turn Python stdlib logging into a proper structured logging library. Rather
than fighting ``logging``, let's live with it.
.. code:: python
import logging
import logstruct
logging.basicConfig(level=logging.INFO)
logging.root.handlers[0].formatter = logstruct.StructuredFormatter()
log = logstruct.getLogger(__name__)
log.info("An info message with data as kwargs", key1="val1", unrepresentable_data=object())
with logstruct.context_scope(worker_number=1):
log.info("Running job", job_name="something")
Features
--------
- Designed to be easy to introduce to existing projects and teams that use stdlib logging. Adding and
configuring this library takes a fraction of the time needed to understand structlog.
- It will work well with any 3rd party libraries that integrate with ``logging``, e.g. Sentry.
- ``StructuredLogger`` - a minimal logger shim to merge log call kwargs into the ``extra`` dict. You can still
use stdlib loggers - the only difference is having to manually pass arbitrary key-value arguments into the
``extra`` dict.
- ``StructuredFormatter`` - a formatter writing log records as JSON or any other format, depending on the
config.
- Console stdout output mode - see ``demo_dev_mode.py``.
- ``context_scope``, ``add_context``, ``remove_context`` - task-safe context vars stack.
Design principles
-----------------
#. Play well with ``logging``.
#. Be small.
Considerations
--------------
If the standard logging library adds a new kwarg to log methods, e.g. ``logging.Logger.info``, this kwarg,
when passed to ``StructuredLogger``, will be merged into the ``extra`` dict until it is added to
``StructuredLogger`` methods. Using ``StructuredLogger`` is optional.
Logging integrations that rely on monkey-patching ``logging.Formatter.format`` won't see it called because
``StructuredFormatter`` doesn't call this method. Such reliance is extremely unlikely.
Development
-----------
.. code:: sh
pip install --editable .[dev]
British English is used in the project, out of fear of losing my settled status.
Raw data
{
"_id": null,
"home_page": null,
"name": "logstruct",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "logging, structured, stdlib",
"author": null,
"author_email": "Karoline Pauls <code@karolinepauls.com>",
"download_url": "https://files.pythonhosted.org/packages/de/ac/0c12b4c9f29452f3c36d5c31895490b5def887c9ff3f535bbb76b042ce3f/logstruct-0.1.tar.gz",
"platform": null,
"description": "logstruct\n=========\n\nEverything you need to turn Python stdlib logging into a proper structured logging library. Rather\nthan fighting ``logging``, let's live with it.\n\n.. code:: python\n\n import logging\n import logstruct\n\n logging.basicConfig(level=logging.INFO)\n logging.root.handlers[0].formatter = logstruct.StructuredFormatter()\n\n log = logstruct.getLogger(__name__)\n log.info(\"An info message with data as kwargs\", key1=\"val1\", unrepresentable_data=object())\n\n with logstruct.context_scope(worker_number=1):\n log.info(\"Running job\", job_name=\"something\")\n\nFeatures\n--------\n\n- Designed to be easy to introduce to existing projects and teams that use stdlib logging. Adding and\n configuring this library takes a fraction of the time needed to understand structlog.\n- It will work well with any 3rd party libraries that integrate with ``logging``, e.g. Sentry.\n- ``StructuredLogger`` - a minimal logger shim to merge log call kwargs into the ``extra`` dict. You can still\n use stdlib loggers - the only difference is having to manually pass arbitrary key-value arguments into the\n ``extra`` dict.\n- ``StructuredFormatter`` - a formatter writing log records as JSON or any other format, depending on the\n config.\n- Console stdout output mode - see ``demo_dev_mode.py``.\n- ``context_scope``, ``add_context``, ``remove_context`` - task-safe context vars stack.\n\nDesign principles\n-----------------\n\n#. Play well with ``logging``.\n#. Be small.\n\nConsiderations\n--------------\n\nIf the standard logging library adds a new kwarg to log methods, e.g. ``logging.Logger.info``, this kwarg,\nwhen passed to ``StructuredLogger``, will be merged into the ``extra`` dict until it is added to\n``StructuredLogger`` methods. Using ``StructuredLogger`` is optional.\n\nLogging integrations that rely on monkey-patching ``logging.Formatter.format`` won't see it called because\n``StructuredFormatter`` doesn't call this method. Such reliance is extremely unlikely.\n\nDevelopment\n-----------\n\n.. code:: sh\n\n pip install --editable .[dev]\n\nBritish English is used in the project, out of fear of losing my settled status.\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Structured stdlib logging",
"version": "0.1",
"project_urls": null,
"split_keywords": [
"logging",
" structured",
" stdlib"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1e00f63bfa16f800f16961b088ecaa72867c5839c2c26da5a37da016e399a9d8",
"md5": "8de2db70c5791c87a13122b22594744c",
"sha256": "d5db4c0a9247baf20dfcf9436014fe9cd1424532164898209ed6dbb2dcb778f1"
},
"downloads": -1,
"filename": "logstruct-0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8de2db70c5791c87a13122b22594744c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 11025,
"upload_time": "2024-08-12T19:01:11",
"upload_time_iso_8601": "2024-08-12T19:01:11.115617Z",
"url": "https://files.pythonhosted.org/packages/1e/00/f63bfa16f800f16961b088ecaa72867c5839c2c26da5a37da016e399a9d8/logstruct-0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "deac0c12b4c9f29452f3c36d5c31895490b5def887c9ff3f535bbb76b042ce3f",
"md5": "3f7bc65ff60ae2c627aa6125179db189",
"sha256": "eb84357578624e553f3c7ad2743a0d7d598894a0c489ec748d91bd0964d1c06f"
},
"downloads": -1,
"filename": "logstruct-0.1.tar.gz",
"has_sig": false,
"md5_digest": "3f7bc65ff60ae2c627aa6125179db189",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 18615,
"upload_time": "2024-08-12T19:01:12",
"upload_time_iso_8601": "2024-08-12T19:01:12.937517Z",
"url": "https://files.pythonhosted.org/packages/de/ac/0c12b4c9f29452f3c36d5c31895490b5def887c9ff3f535bbb76b042ce3f/logstruct-0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-12 19:01:12",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "logstruct"
}