{ "info": { "author": "Zaar Hai", "author_email": "haizaar@haizaar.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 3.7" ], "description": "**********************************************\nUberlogging - Python logging the way I like it\n**********************************************\n\nHighly opinionated wrapper/configuration around\n`structlog `_ and stdlib logger.\n\nPython 3.7+ only. To use contextvar, minimum Python 3.7.1 is required.\n\nWhy\n###\nEvery project starts with burden of logging configuration.\nWe want colors for interactive debugging, plain text in local\ndev when redirecting to file, and JSON when running in production\nwith central log collection system. Finally, I like\n`structlog `_,\nbut most of the libraries do not use it, so I need to configure\nboth libraries in compatible way.\n\nThis library does exactly that - configures logging as described\nabove. It does it both for structlog and standard library logging.\n\nOpinionated?\n############\nYes it is, since it merely configures great tools written by\nother great people to behave the way I personally prefer.\n\nFor instance, I prefer *not* to render structlog's key/val\narguments as separate attributes in JSON output, since I find\nit much more convenient to read them as part of the text message,\neven in centralized logging UIs such as Graylog - processing them\nas separate fields will require me to enable million field columns,\nsince each log message has its own context; and I don't use logs,\nbut metrics for broader analysis.\n\nUsage\n#####\n.. code:: python\n\n import uberlogging\n uberlogging.configure()\n\nThat's all. You are ready to go. Simply import ``structlog`` or stdlib\n``logging``, create your logger and start writing your app.\n\n.. code:: python\n\n import structlog\n logger = structlog.get_logger(\"main\")\n logger.info(\"Rocky road\", to=\"Dublin\")\n\nDefine ``UBERLOGGING_FORCE_TEXT=1`` environment variable\nto force text output in non-tty streams. Useful for local environments when\nrunning your app with output redirection.\n\nFormatting\n##########\nStructlog's context (key/value pairs passed to logging call) is rendered as\n``= =`` (or empty string otherwise) and is\navailable as ``{context}`` formatting variable. If non empty it will be\n4-space padded (yes, it's not generic, but I find it very convenient with\nthe default configuration).\n\nIf you employ contextvars, they will be rendered similarly and available as\n``{contextvars}}`` formatting variable. Similarly, it's either single or\n4-space padded depending whether exists non-empty structlog context for the\ncurrent log record. See dedicated section on contextvars below.\n\nEnvrionment overrides\n#####################\nSometimes people want things their own way and that's without changing actual code.\nTo address that uberlogging provides ability to control some of its configuration\nthough environment variables:\n\n``UBERLOGGING_FORCE_TEXT``\n Define to non-empty value to force textual (not JSON) output. Colouring is autodetected\n\n``UBERLOGGING_FORCE_TEXT_COLOR``\n Same as above, but with with colours always *enabled*\n\n``UBERLOGGING_FORCE_TEXT_NO_COLOR``\n Same as above, but with with colours always *disabled*\n\n``UBERLOGGING_MESSAGE_FORMAT``\n String that overrides logging message format.\n E.g. ``\"{asctime} {levelname} {message}``. Note that only \"{\"\n `styles `_\n are supported.\n\nContextual logging\n##################\nStructlogs's ``logger.bind(request_id=\"foo\")`` is great for simple things but when you have\nmulti-layer request handling, passing the same instance of bound logger is a). cumbersome and\nb). requires the same logger to be used by everything that handles the request.\n\nI've long missed log4cxx `Nested Diagnostic Contexts `_\nin Python and now with contextvars we can finally achieve that. The best part is that it\nworks both in threaded and asyncio code!\n\nIf you never heard of contextvars, please read official\n`documentation `_. In the nutshell\nit \"kinda\" replaces thread local storage and is natively supported in asyncio, i.e.\nit's both thread-safe and concurrent safe.\n\nTo employ contextvars in uberlogging you need to:\n\n* Create a contextvar somewhere in your code\n* Pass this context var to ``uberlogging.configure()``\n* Set contextvar values whenever your like and all subsequent log messages will\n have its value rendered as part of the ``contextvar`` extra section\n\nHere is an example:\n\n.. code-block:: python\n\n import asyncio\n from contextvars import ContextVar\n\n import structlog\n import uberlogging\n\n ctx_request_id: ContextVar = ContextVar(\"request_id\")\n logger = structlog.get_logger(__name__)\n\n\n async def handle_request(request_id: str) -> None:\n ctx_request_id.set(request_id)\n logger.info(\"Handling request\") # Will produce \"Handling request request_id=\n\n\n async def server():\n logger.info(\"Main server handling two requests\")\n t1 = asyncio.create_task(handle_request(\"Zf1glE\"))\n t2 = asyncio.create_task(handle_request(\"YcEf73\"))\n await asyncio.wait((t1, t2))\n logger.info(\"Main server done\")\n\n if __name__ == \"__main__\":\n uberlogging.configure(contextvars=(ctx_request_id,))\n asyncio.run(server())\n\nThis code will produce the following::\n\n 2019-10-07T13:41:17.669 __main__ INFO ## Main server handling two requests ctx.server:17\n 2019-10-07T13:41:17.669 __main__ INFO ## Handling request request_id='Zf1glE' ctx.handle_request:13\n 2019-10-07T13:41:17.669 __main__ INFO ## Handling request request_id='YcEf73' ctx.handle_request:13\n 2019-10-07T13:41:17.669 __main__ INFO ## Main server done ctx.server:21\n\nNote that logger invocations inside the request handler do not mention any ``request_id`` - it's\ninjected by logging formatter from the context.\n\n\nWhere are tests?\n################\nNo tests, only deadlines :)\nSeriously though, there is ``demo.sh`` script that's good enough for now, since\nthis library is not going to see much of a development.\n\nTested on Python3.6+ only! Stream configuration only works on Python 3.7+.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/haizaar/uberlogging", "keywords": "", "license": " Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"{}\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright {yyyy} {name of copyright owner}\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n", "maintainer": "", "maintainer_email": "", "name": "uberlogging", "package_url": "https://pypi.org/project/uberlogging/", "platform": "", "project_url": "https://pypi.org/project/uberlogging/", "project_urls": { "Homepage": "https://github.com/haizaar/uberlogging" }, "release_url": "https://pypi.org/project/uberlogging/0.6.3/", "requires_dist": null, "requires_python": "", "summary": "Highly opinionated logging configurator", "version": "0.6.3" }, "last_serial": 5982391, "releases": { "0.4.0": [ { "comment_text": "", "digests": { "md5": "51035b9d1720c82fb089deb57d01cec3", "sha256": "056ae9c4bf767ea4e0cd9ba8cd7d2ef1883effd4d5e087a087fcc8b68a00f227" }, "downloads": -1, "filename": "uberlogging-0.4.0.tar.gz", "has_sig": false, "md5_digest": "51035b9d1720c82fb089deb57d01cec3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9783, "upload_time": "2019-03-29T03:04:59", "url": "https://files.pythonhosted.org/packages/d7/4d/a4255dcf2558262939988298b1777f95ab3ed51339ab675cf159c20ba981/uberlogging-0.4.0.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "79bfcd408af6920c9bcb7c79960740c0", "sha256": "6e9ff8e1517f760928e1dadb637558409f2950497f620bacf286f0cabb7f6020" }, "downloads": -1, "filename": "uberlogging-0.4.2.tar.gz", "has_sig": false, "md5_digest": "79bfcd408af6920c9bcb7c79960740c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9950, "upload_time": "2019-03-29T03:19:02", "url": "https://files.pythonhosted.org/packages/7b/02/6bc8a4cb4821c768d62056db4bed4dd72e1c127c67d7c787086765ca47e1/uberlogging-0.4.2.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "056a01d0a8351688da65b559cc734cb9", "sha256": "5eded894192f4356c5de8986d71c4f8598b13701ce57337b247f32a62f12865e" }, "downloads": -1, "filename": "uberlogging-0.5.0.tar.gz", "has_sig": false, "md5_digest": "056a01d0a8351688da65b559cc734cb9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13862, "upload_time": "2019-04-09T02:44:43", "url": "https://files.pythonhosted.org/packages/d6/ba/3c54ad9312c0050f1c1f8b555de6919a5b5e57992410f30e5c6334209ce0/uberlogging-0.5.0.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "6de3e7b5f55caca44d804bb7c23b8550", "sha256": "fd1c793b1bbb7822131aff2aba8829cadc5d0d843cb12aa0cae1de76c4a8c7aa" }, "downloads": -1, "filename": "uberlogging-0.6.0.tar.gz", "has_sig": false, "md5_digest": "6de3e7b5f55caca44d804bb7c23b8550", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17452, "upload_time": "2019-10-07T04:00:51", "url": "https://files.pythonhosted.org/packages/cf/91/9a65458dbdb5395ea93eb236af8080114d5b29e656892e5496ad537d3449/uberlogging-0.6.0.tar.gz" } ], "0.6.1": [ { "comment_text": "", "digests": { "md5": "78f82381d754a8c41dc97896dd5d780a", "sha256": "3a5d325a22c984641440c388b85b7cafa1adda148cdb81583672d93b0758298b" }, "downloads": -1, "filename": "uberlogging-0.6.1.tar.gz", "has_sig": false, "md5_digest": "78f82381d754a8c41dc97896dd5d780a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17832, "upload_time": "2019-10-08T02:29:44", "url": "https://files.pythonhosted.org/packages/df/02/5c23ab5294f0c410fdd716766c78c491c5502b171f5b92893ed709ebfb64/uberlogging-0.6.1.tar.gz" } ], "0.6.2": [ { "comment_text": "", "digests": { "md5": "3a30ecf88b57fb0d27ae2f5e30b45732", "sha256": "afa68cc803d2b05ea1a11beb1da2abdec0c3bf1068e8566c7bf8a98fc5f63bc0" }, "downloads": -1, "filename": "uberlogging-0.6.2.tar.gz", "has_sig": false, "md5_digest": "3a30ecf88b57fb0d27ae2f5e30b45732", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17831, "upload_time": "2019-10-15T05:26:04", "url": "https://files.pythonhosted.org/packages/d3/5b/5c4b913349b8e27b79d59ccdb853685b55e4fbade07448a1f423dc4a4791/uberlogging-0.6.2.tar.gz" } ], "0.6.3": [ { "comment_text": "", "digests": { "md5": "7c224187e6d976e4d16c7a219d391a9a", "sha256": "6be040f96c89ec5d1feb3b9cd5d204535c52e78cce96b041c2e9b0295f84abb1" }, "downloads": -1, "filename": "uberlogging-0.6.3.tar.gz", "has_sig": false, "md5_digest": "7c224187e6d976e4d16c7a219d391a9a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17843, "upload_time": "2019-10-16T10:18:23", "url": "https://files.pythonhosted.org/packages/8f/85/2aed79112b2aa8360d861cb30898e3cff5b6d8d1ed2f6ca8b8ec7fee8274/uberlogging-0.6.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7c224187e6d976e4d16c7a219d391a9a", "sha256": "6be040f96c89ec5d1feb3b9cd5d204535c52e78cce96b041c2e9b0295f84abb1" }, "downloads": -1, "filename": "uberlogging-0.6.3.tar.gz", "has_sig": false, "md5_digest": "7c224187e6d976e4d16c7a219d391a9a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17843, "upload_time": "2019-10-16T10:18:23", "url": "https://files.pythonhosted.org/packages/8f/85/2aed79112b2aa8360d861cb30898e3cff5b6d8d1ed2f6ca8b8ec7fee8274/uberlogging-0.6.3.tar.gz" } ] }