{ "info": { "author": "Bernhard C. Thiel", "author_email": "thiel@tbi.univie.ac.at", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5" ], "description": "Self-logging exceptions\n=======================\n\n* `Source on GitHub `_\n\nInstallation\n------------\n\n\nUse setup.py :\n\n.. code-block:: bash\n\n python setup.py install\n\nWarning\n-------\n\nThis module modifies `sys.excepthook` when it is imported!\n\nUsage\n-----\n\nSelf-logging exceptions\n~~~~~~~~~~~~~~~~~~~~~~~\n\nAttach a log message to an exception:\n\n.. code-block:: python\n\n import logging\n import logging_exceptions as exlog\n\n e = ValueError(\"Wrong value\")\n logger = logging.getLogger(__name__)\n with exlog.log_to_exception(logger, e):\n logger.critical(\"This is a %s log mressage\", \"long\")\n raise e # The exception can also be raised inside the with statement\n\n\nIf the error is not caught, the log message will be displayed upon program\ntermination.\n\nCatch the error and display the log message at a costum log-level:\n\n.. code-block:: python\n\n import logging_exceptions as exlog\n import logging\n try:\n e = ValueError(\"Wrong value\")\n logger = logging.getLogger(__name__)\n with exlog.log_to_exception(logger, e):\n logger.critical(\"This is a %s log mressage\", \"long\")\n raise e\n except ValueError as err:\n exlog.log(err, level=logging.DEBUG, with_stacktrace=False)\n\nHere, `exlog.log` is a synonym for `exlog.log_exception`\n\nLogging from a different function name and line number\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe code in log_exception calls the `_log` function of a Logger object.\nTo avoid recording the function name and line number of `log_to_exception`,\n`logging_exception` calls `logging.setLoggerClass(ExlogLogger)` to set the\nclass for all loggers created after import of `logging_exception` to `ExlogLogger`.\n\n`ExlogLogger` is a subclass of `logging.Logger` defined by this module. It\noverrides `findCaller` to have more control over the recorded caller.\nIn addition to ignoring functions defined inside `logging_exceptions`,\n`ExlogLogger` classes have the public attribute `ignored_functions`.\n\nBy adding function names to `ignored_functions`, it is possible to record\nmatching function's parents instead of matching functions as the caller.\n\nIn particular, the context manager `logging_exceptions.log_at_caller` can be used\nin helper functions to temporarily update a logger's `ignored_functions` in order to record a function's caller instead of the function.\n\nThe following code will emit a log message with the function name set to \n`foo`, not `helper_function`:\n\n .. code-block:: python\n\n import logging_exceptions as exlog\n logger = logging.get_logger(__name__)\n def helper_function():\n with exlog.log_at_caller(logger):\n logger.log(\"This is a log message\")\n def foo():\n helper_function()\n\n\n\nCommandline convenience functions\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe following convenience functions are not directly related to exceptions,\nbut useful if you use argparse.\n\nAdd the '--verbose', '--debug' and '--quiet' options to an\nargparse.Argumentparser instance.\n\n.. code-block:: python\n\n import argparse\n import logging_exceptions as exlog\n\n parser=argparse.ArgumentParser(\"Some help text\")\n exlog.update_parser(parser)\n args = parser.parse_args()\n\n logging.basicConfig()\n # The following call updates the log levels of the root logger\n # and potential some other loggers.\n exlog.config_from_args(args)\n\nNow the script can be used from the commandline like this:\n\n.. code-block:: bash\n\n # Set the log-level for the loggers with the names `path.to.module1`\n # and `path.to.module2` to DEBUG.\n python script.py --debug path.to.module1,path.to.module2\n\nExamples\n--------\n\nSee the file 'logging_exceptions_examples.py'\n\nComparison to logging.handlers.MemoryHandler\n--------------------------------------------\n\nThe logging.handlers module contains a handler for a similar purpose: The MemoryHandler.\nIt buffers log messages and only emits them, if a log record of severity error or above is encountered.\nI will quickly explain the differences between MemoryHandler and my module:\n\nMemoryHandler is great if you know that an event of severity ERROR may occur\nin the future (typically in the same function) and you want to prepare for\nthis potential exception. Typically, you know the scope for which the exceptions\nhave to be buffered and you know when the buffered exceptions are no longer needed and can be discarded.\n\nWhile for MemoryHandler the error condition is rather unspecific, the scope in\nwhich we have to decide between discarding and emitting the log messages is well\nknown.\n\nThe `log_to_exception` decorator, on the other hand, is useful if the exception\nis well specified (it is already created/ caught), but the the scope in which\nthe exception may or may not be caught is unspecified. Examples would be\nlibrary functions that raise an error.\n\nA typical example would be the following:\n\n.. code-block:: python\n\n import logging\n from logging_exceptions import log_to_exception\n\n # Whoever calls public_function may want to catch the ValueError and hide\n # the log messages or change their level to logging.DEBUG\n def public_function():\n logger = logging.getLogger(__name__)\n a = some_complex_calculation(12)\n try:\n some_function(a)\n except ValueError as e:\n with log_to_exception(logger, e):\n log.error(\"While calling `some_function` with %s, \"\n \"which is result of `some_complex_calculation`(%d),\"\n \" an error occurred\", a, 12)\n raise\n\n\nCompatibility\n-------------\n\nCompatible with python 2.7 and python 3\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Bernhard10/logging_exceptions", "keywords": "logging exceptions", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "logging-exceptions", "package_url": "https://pypi.org/project/logging-exceptions/", "platform": "", "project_url": "https://pypi.org/project/logging-exceptions/", "project_urls": { "Homepage": "https://github.com/Bernhard10/logging_exceptions" }, "release_url": "https://pypi.org/project/logging-exceptions/0.1.8/", "requires_dist": null, "requires_python": "", "summary": "Self-logging exceptions: Attach log messages to exceptions and output them conditionally.", "version": "0.1.8" }, "last_serial": 3820242, "releases": { "0.1.4": [ { "comment_text": "", "digests": { "md5": "8786cbde11ce60a634e6a1760b8768f8", "sha256": "4254b82b5ee13e8dc12caeb9eea9391f321b98daf6650911cd52ed8b575fa420" }, "downloads": -1, "filename": "logging_exceptions-0.1.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8786cbde11ce60a634e6a1760b8768f8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7857, "upload_time": "2017-06-19T14:18:24", "url": "https://files.pythonhosted.org/packages/fd/db/f67ea893b76ce3508f61eb4c456c7bc77f94a7cdc197d5ee53f5f4df9499/logging_exceptions-0.1.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7eb5ac02c4bbcc6e9fe0aba1b2348120", "sha256": "352b8beecdf4358ea5f2ee3dc6dfdf99a24a7a366d84f0d8812ebcd9fa3d1262" }, "downloads": -1, "filename": "logging_exceptions-0.1.4.tar.gz", "has_sig": true, "md5_digest": "7eb5ac02c4bbcc6e9fe0aba1b2348120", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5294, "upload_time": "2017-06-19T14:18:25", "url": "https://files.pythonhosted.org/packages/4b/2a/1de1c7bd87126ffddaf01221650521ffd0aef5c39e5e1ae08126f0a4710b/logging_exceptions-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "020cb8a4c23bbb8a9704837a3bb9de0d", "sha256": "6be9512f92ded4911e30ef80e5e1db51a1dabc8196bd351334bd24ff2977a382" }, "downloads": -1, "filename": "logging_exceptions-0.1.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "020cb8a4c23bbb8a9704837a3bb9de0d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7893, "upload_time": "2017-07-26T22:33:24", "url": "https://files.pythonhosted.org/packages/b2/1a/b958c17050acc6116b3b030cf0ef06cad7a15a3b59214204d33e5e06a48d/logging_exceptions-0.1.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0bac6225aa560b95997be13a467aece4", "sha256": "83c2d673710e7fbbc13fc3ba2616bf70dda69494d6fe90b3c52ea7dfffe292ae" }, "downloads": -1, "filename": "logging_exceptions-0.1.5.tar.gz", "has_sig": true, "md5_digest": "0bac6225aa560b95997be13a467aece4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5332, "upload_time": "2017-07-26T22:33:27", "url": "https://files.pythonhosted.org/packages/91/2a/f388959962f606657d4be1eae0232919693692d48e12ed3bb00d0b947f87/logging_exceptions-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "46be88adb3ae1f923af099ff0c90e33a", "sha256": "b9d2f8148a73efd416335a646c52fb216177a4be23c1adb179da1c45dc68564c" }, "downloads": -1, "filename": "logging_exceptions-0.1.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "46be88adb3ae1f923af099ff0c90e33a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9951, "upload_time": "2017-07-28T10:58:13", "url": "https://files.pythonhosted.org/packages/a9/20/ce22ce747c89a56905944b664c863de39968ec41aaecdf2ae9f49ba79a7c/logging_exceptions-0.1.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0df712e060b3aa8cdc8e8c303fd361a3", "sha256": "1d05a68f96c8b8e5a41837b83acd329e46800895ea13b0cc7dfb291ce67b0b84" }, "downloads": -1, "filename": "logging_exceptions-0.1.6.tar.gz", "has_sig": true, "md5_digest": "0df712e060b3aa8cdc8e8c303fd361a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7563, "upload_time": "2017-07-28T10:58:16", "url": "https://files.pythonhosted.org/packages/af/fb/bc63328d1c22142c73fe441653abdca3664ac2c6fa49dbf9d157bc857454/logging_exceptions-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "3ee6ac4028c2cb7e283a68f6819a1fe4", "sha256": "acc19fd2ab2921101216a67fe3d355bcde8f9223d512bfc6d1b0f2c71cec9ba4" }, "downloads": -1, "filename": "logging_exceptions-0.1.7-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "3ee6ac4028c2cb7e283a68f6819a1fe4", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10129, "upload_time": "2018-04-26T12:22:11", "url": "https://files.pythonhosted.org/packages/64/28/bf90b0cd5d90dbbab9fd166c0b50b69a054770b23a8c114885ad2db94051/logging_exceptions-0.1.7-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ba4f843a6381747a38a797889bb4cd52", "sha256": "e8ea9e48b7dd75eb97ed09064f79f3b05c8cbfda986592ff932c3700c4ad24e3" }, "downloads": -1, "filename": "logging_exceptions-0.1.7-py3.5.egg", "has_sig": false, "md5_digest": "ba4f843a6381747a38a797889bb4cd52", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 11572, "upload_time": "2018-04-26T12:22:13", "url": "https://files.pythonhosted.org/packages/32/fd/64e0916b57a50ef51058053fd49d65d610c4051063ee2854fe8ea1cbf032/logging_exceptions-0.1.7-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "03cba0bd91efbf0c1e07ee0a89aa37ed", "sha256": "6453acb0d4e435866ee0869a77a5801e4fd16c0e7a803a3c74c53fb15b981c68" }, "downloads": -1, "filename": "logging_exceptions-0.1.7.tar.gz", "has_sig": true, "md5_digest": "03cba0bd91efbf0c1e07ee0a89aa37ed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8417, "upload_time": "2018-04-26T12:22:14", "url": "https://files.pythonhosted.org/packages/59/65/2a50cb58001f49ae7744058ed2e18b39b2841e7ef3938b3b9567b4634338/logging_exceptions-0.1.7.tar.gz" } ], "0.1.8": [ { "comment_text": "", "digests": { "md5": "74337381c37ad61ebaa532f563a70124", "sha256": "e0d2ba8d266f9e258b5cbc117c6264128883c5ba17605c83f3818f9f8e6a4b02" }, "downloads": -1, "filename": "logging_exceptions-0.1.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "74337381c37ad61ebaa532f563a70124", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10129, "upload_time": "2018-04-30T09:05:28", "url": "https://files.pythonhosted.org/packages/9c/d8/6d94dfd3bba77c4e2a4eb749291125018a010b1ac7fdee811074e7a4b73c/logging_exceptions-0.1.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "62b7b8ff2c397bd9ae344acb0ed4e185", "sha256": "0901b54a757af4288d39b12e9f8a8abe094b86cfb739c0428a907bdd17b3763e" }, "downloads": -1, "filename": "logging_exceptions-0.1.8.tar.gz", "has_sig": true, "md5_digest": "62b7b8ff2c397bd9ae344acb0ed4e185", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8419, "upload_time": "2018-04-30T09:05:30", "url": "https://files.pythonhosted.org/packages/28/49/336febb1764f7c2648b7961a595da5d65a6ac2502947816eb318f07ecb1d/logging_exceptions-0.1.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "74337381c37ad61ebaa532f563a70124", "sha256": "e0d2ba8d266f9e258b5cbc117c6264128883c5ba17605c83f3818f9f8e6a4b02" }, "downloads": -1, "filename": "logging_exceptions-0.1.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "74337381c37ad61ebaa532f563a70124", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 10129, "upload_time": "2018-04-30T09:05:28", "url": "https://files.pythonhosted.org/packages/9c/d8/6d94dfd3bba77c4e2a4eb749291125018a010b1ac7fdee811074e7a4b73c/logging_exceptions-0.1.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "62b7b8ff2c397bd9ae344acb0ed4e185", "sha256": "0901b54a757af4288d39b12e9f8a8abe094b86cfb739c0428a907bdd17b3763e" }, "downloads": -1, "filename": "logging_exceptions-0.1.8.tar.gz", "has_sig": true, "md5_digest": "62b7b8ff2c397bd9ae344acb0ed4e185", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8419, "upload_time": "2018-04-30T09:05:30", "url": "https://files.pythonhosted.org/packages/28/49/336febb1764f7c2648b7961a595da5d65a6ac2502947816eb318f07ecb1d/logging_exceptions-0.1.8.tar.gz" } ] }