{ "info": { "author": "Evgeniy Afonasev", "author_email": "ea.afonasev@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "# context_logging\n\n[![pypi](https://badge.fury.io/py/context_logging.svg)](https://pypi.org/project/context_logging)\n[![Python: 3.7+](https://img.shields.io/badge/Python-3.7+-blue.svg)](https://pypi.org/project/context_logging)\n[![Downloads](https://img.shields.io/pypi/dm/context_logging.svg)](https://pypistats.org/packages/context_logging)\n[![Build Status](https://travis-ci.org/Afonasev/context_logging.svg?branch=master)](https://travis-ci.org/Afonasev/context_logging)\n[![Code coverage](https://codecov.io/gh/Afonasev/context_logging/branch/master/graph/badge.svg)](https://codecov.io/gh/Afonasev/context_logging)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://en.wikipedia.org/wiki/MIT_License)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n\n## Description\n\nTool for easy logging with current context information\n\n## Installation\n\n pip install context_logging\n\n## Usage\n\n### As contextmanager\n\n```python\nfrom context_logging import Context, current_context\n\nwith Context(val=1):\n assert current_context['val'] == 1\n\nassert 'val' not in current_context\n```\n\n### Any nesting of contexts is allowed\n\n```python\nwith Context(val=1):\n assert current_context == {'val': 1}\n\n with Context(val=2, var=2):\n assert current_context == {'val': 2, 'var': 2}\n\n assert current_context == {'val': 1}\n\nassert 'val' not in current_context\n```\n\n### As decorator\n\n```python\n@Context(val=1)\ndef f():\n assert current_context['val'] == 1\n\nf()\nassert 'val' not in current_context\n```\n\n### With start/finish\n\n```python\nctx = Context(val=1)\nassert 'val' not in current_context\n\nctx.start()\nassert current_context['val'] == 1\n\nctx.finish()\nassert 'val' not in current_context\n```\n\n### Write/delete to current_context\n```python\nwith Context():\n assert 'val' not in current_context\n current_context['val'] = 1\n assert current_context['val'] == 1\n```\n\n### Explicit context name (else will be used path to the python module)\n\n```python\nwith Context(name='my_context'):\n pass\n```\n\n### Setup logging with context\n\n```python\nimport logging\nfrom context_logging import current_context, setup_log_record\n\nlogging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s %(context)s', level=logging.INFO)\nsetup_log_record()\n\ncurrent_context['val'] = 1\nlogging.info('message')\n\n# 2019-07-25 19:49:43,892 INFO root message {'val': 1}\n```\n\n### Execution time logged on exit from context (disable with `log_execution_time=False`)\n\n```python\nwith Context(name='my_context'):\n time.sleep(1)\n\n# INFO 'my_context: executed in 00:00:01',\n```\n\n### Exceptions from context are populated with current_contextdisable with `fill_exception_context=False`)\n\n```python\ntry:\n with Context(val=1):\n raise Exception(1)\nexcept Exception as exc:\n assert exc.args = (1, {'val': 1})\n```\n\n### We can set data to root context that never will be closed\n\n```python\nfrom context_logging import root_context\n\nroot_context['env'] = 'test'\n```\n\n### For autofilling thread context in async code\n\n```python\nfrom contextvars_executor import ContextVarExecutor\n\nloop.set_default_executor(ContextVarExecutor())\n```\n\n## For developers\n\n### Create venv and install deps\n\n make init\n\n### Install git precommit hook\n\n make precommit_install\n\n### Run linters, autoformat, tests etc.\n\n make pretty lint test\n\n### Bump new version\n\n make bump_major\n make bump_minor\n make bump_patch\n\n## License\n\nMIT\n\n## Change Log\n\nUnreleased\n-----\n\n* ...\n\n1.0.0 - 2019-07-29\n-----\n\n* no show empty context in log\n\n0.2.0 - 2019-07-25\n-----\n\n* context as attr of log record\n\n0.1.0 - 2019-07-23\n-----\n\n* initial\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://pypi.org/project/context_logging", "keywords": "", "license": "MIT", "maintainer": "Evgeniy Afonasev", "maintainer_email": "ea.afonasev@gmail.com", "name": "context-logging", "package_url": "https://pypi.org/project/context-logging/", "platform": "", "project_url": "https://pypi.org/project/context-logging/", "project_urls": { "Homepage": "https://pypi.org/project/context_logging", "Repository": "https://github.com/Afonasev/context_logging" }, "release_url": "https://pypi.org/project/context-logging/1.0.0/", "requires_dist": null, "requires_python": ">=3.7,<4.0", "summary": "Tool for easy logging with current context information", "version": "1.0.0" }, "last_serial": 5598410, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "2b1f64588ddbe60ba94a0b4b80dcc0e7", "sha256": "49422a1f2e5b0a53b83aa7eaa99426ff7a29e3d6c74f8d1214ab7386b9ea5769" }, "downloads": -1, "filename": "context_logging-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2b1f64588ddbe60ba94a0b4b80dcc0e7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 4804, "upload_time": "2019-07-23T08:39:14", "url": "https://files.pythonhosted.org/packages/46/02/b9ea84d8230be05e01ac90f71cad0965ab69ef15bbb8758e6e36609e817c/context_logging-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "33aab2b247050b3abd675b05f90777ea", "sha256": "c309dc4af5c09ab74245235a082fcb65be363fc7d55eeda281690eb4f1b3aced" }, "downloads": -1, "filename": "context_logging-0.1.0.tar.gz", "has_sig": false, "md5_digest": "33aab2b247050b3abd675b05f90777ea", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 4480, "upload_time": "2019-07-23T08:39:17", "url": "https://files.pythonhosted.org/packages/4e/bf/71ae36d4013d2531f3cc9369175d1df19719a61d57129118676fcef29c06/context_logging-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "1f9a2d154a44d9a122f7d0b1aaa3fea0", "sha256": "5d70ad193e9baea41b4c702f389f491348c0db82ac18a7e0992dcc36b4e14665" }, "downloads": -1, "filename": "context_logging-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1f9a2d154a44d9a122f7d0b1aaa3fea0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 4910, "upload_time": "2019-07-25T15:25:17", "url": "https://files.pythonhosted.org/packages/5a/50/249f206cf7834f7b7a94b59a72a9dac200747b6c32e6bf84f66160466e8a/context_logging-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0364a4320be52417f9bd37287ea84f61", "sha256": "b6479ef802238151081b220da594a979be56e5d6340a19488c8ba4bc93120ba6" }, "downloads": -1, "filename": "context_logging-0.2.0.tar.gz", "has_sig": false, "md5_digest": "0364a4320be52417f9bd37287ea84f61", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 4653, "upload_time": "2019-07-25T15:25:19", "url": "https://files.pythonhosted.org/packages/8f/13/b3b35d725a05209adf9ad55b6ccd9fea0865c773bc31f467d2cb5b7cc914/context_logging-0.2.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "fe0526f1f6d9288551155e5c1c5ad183", "sha256": "af5fafcec60ab07b414b0092246d5e876a126c7a8413efaa8c02e3594471c533" }, "downloads": -1, "filename": "context_logging-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fe0526f1f6d9288551155e5c1c5ad183", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 4937, "upload_time": "2019-07-29T09:04:09", "url": "https://files.pythonhosted.org/packages/b9/d7/81fbe4f582fef3efd1f26a95fd54dae29a2f46c33a348bcd39e113a24a6a/context_logging-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "87fd95a483ead20f821b3640ffe8bb8c", "sha256": "ee556f81886bcd31a4f7250f4a8e996fc9b51942955f84db4d01d0c8e9d98749" }, "downloads": -1, "filename": "context_logging-1.0.0.tar.gz", "has_sig": false, "md5_digest": "87fd95a483ead20f821b3640ffe8bb8c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 4692, "upload_time": "2019-07-29T09:04:10", "url": "https://files.pythonhosted.org/packages/60/ee/18336c06fcf9f340b5bc20e5fb052e28f71a892ca90f84b6b9b82758644b/context_logging-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fe0526f1f6d9288551155e5c1c5ad183", "sha256": "af5fafcec60ab07b414b0092246d5e876a126c7a8413efaa8c02e3594471c533" }, "downloads": -1, "filename": "context_logging-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fe0526f1f6d9288551155e5c1c5ad183", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 4937, "upload_time": "2019-07-29T09:04:09", "url": "https://files.pythonhosted.org/packages/b9/d7/81fbe4f582fef3efd1f26a95fd54dae29a2f46c33a348bcd39e113a24a6a/context_logging-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "87fd95a483ead20f821b3640ffe8bb8c", "sha256": "ee556f81886bcd31a4f7250f4a8e996fc9b51942955f84db4d01d0c8e9d98749" }, "downloads": -1, "filename": "context_logging-1.0.0.tar.gz", "has_sig": false, "md5_digest": "87fd95a483ead20f821b3640ffe8bb8c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 4692, "upload_time": "2019-07-29T09:04:10", "url": "https://files.pythonhosted.org/packages/60/ee/18336c06fcf9f340b5bc20e5fb052e28f71a892ca90f84b6b9b82758644b/context_logging-1.0.0.tar.gz" } ] }