{ "info": { "author": "Tobias Hommel", "author_email": "software@genoetigt.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "logex\n=====\n\n.. contents::\n\nLogex is a python module to easily add logging for unhandled exceptions in\nD-Bus, thread and other functions.\nIt can also be quite helpful when developing with the new asyncio module of\npython 3.4. Although this module does some sort of exception logging, it can\neasily happen that exceptions are accidentally swallowed.\nAlthough unhandled exceptions get written to STDERR by default and most modules\nprovide some mechanism to log these, this is not always sufficient, e.g. when\ninside a daemon which discards all default output.\nSometimes it may also be desirable to automatically send an email if some\nexception occurs or at least write some kind of audit log.\n\nThis modlue comes with a decorator function which can be applied on demand. It\nprovides advanced debugging information which gives you the most relevant\ninformation for each frame in the exception's traceback.\n\n========\nSettings\n========\n\nA description of all available settings is available in the source\ndocumentation of the `log()` function in the `logex.py `_ module.\n\nAll settings can be set \"globally\", e.g. by using:\n\n.. code:: python\n\n import logex\n logex.VIEW_SOURCE = True\n\nor they can be specified when decorating a function or method:\n\n.. code:: python\n\n import logex\n @logex.log(view_source=True)\n def f():\n pass\n\nCurrently available module variables and their defaults:\n\n- ``LOGFUNCTION = logging.error``\n- ``TEMPLATE = ('Unhandled exception calling %(funcname)s(%(argsview)s):\\n%(traceback)s\\n%(sourceview)s')``\n- ``ADVANCED = False``\n- ``LAZY = False``\n- ``RERAISE = True``\n- ``CATCHALL = False``\n- ``VIEW_SOURCE = False``\n- ``DETECT_NESTED = True``\n\nThe default behaviour of the log() decorator is to generate a log message using\n``TEMPLATE`` and pass this to ``LOGFUNCTION``.\nFor a list of place holders that are replaced, see the `generate_log_message()`\nfunction in `logex.py `_.\n\nSetting ``ADVANCED`` to True, gives you the opportunity to use a logging function\nwhich interprets the exception data itself. For a description of the arguments\nto an advanced logging function, see the `generate_log_message()` function in\n`logex.py `_.\n\nIf ``LAZY`` is True, the logging function itself must return another function\nobject which is then used as the actual logging function.\n\n``RERAISE`` can be set to False to only log the exception and continue \"normally\".\nThis will, of course, not resume the decorated function itself, but return to\nthe caller of this function and resume execution there.\n\nIf ``CATCHALL`` is True, all exceptions are caught, i.e. also KeyboardInterrupt,\nSystemExit and GeneratorExit.\n\n``VIEW_SOURCE`` can be used to show the source code and local variables for every\nfunction in the exceptions traceback.\n\nlogex will usually detect if an exception occurs in a logex-decorated function\nwhich, in turn, was called by a logex-decorated function and shorten the output\nso you do not get the same source view twice. ``DETECT_NESTED`` can be used to\ndisable this feature and always print the full source view.\n\n=======\nExample\n=======\nSeveral examples can be found in the ``examples`` directory, so we show just some\nsimple usage here:\n\n.. code:: python\n\n #!/usr/bin/python\n import logex\n\n @logex.log\n def my_function():\n raise Exception(\"something bad happens here\")\n\n my_function()\n\nThis will simply print the exception traceback, like this:\n\n.. code:: python\n\n ERROR:root:Unhandled exception calling my_function():\n Traceback (most recent call last):\n File \"./x.py\", line 10, in my_function\n do_something_dangerous()\n File \"./x.py\", line 5, in do_something_dangerous\n raise Exception(\"something bad happens here\")\n Exception: something bad happens here\n \n \n Traceback (most recent call last):\n File \"./x.py\", line 13, in \n my_function()\n File \"/home/tobi/repos/logex/logex.py\", line 318, in wrapper_f\n template, view_source, reraise, wrapper_code=wrapper_code)\n File \"/home/tobi/repos/logex/logex.py\", line 306, in wrapper_f\n wrapped_f(*args, **kwargs)\n File \"./x.py\", line 10, in my_function\n do_something_dangerous()\n File \"./x.py\", line 5, in do_something_dangerous\n raise Exception(\"something bad happens here\")\n Exception: something bad happens here\n\nThe second traceback is the one generated because an unhandled exception\noccurs(logex reraises exceptions by default), it also contains some extra\nframes generated by the logex decorator.\nLet's make it a bit more advanced and pleasant to read:\n\n.. code:: python\n\n #!/usr/bin/python\n import logex\n\n @logex.log(view_source=True, reraise=False)\n def my_function():\n x = 1\n raise Exception(\"something bad happens here\")\n\n my_function()\n\nThis yields:\n\n.. code:: python\n\n ERROR:root:Unhandled exception calling my_function():\n Traceback (most recent call last):\n File \"./x.py\", line 10, in my_function\n do_something_dangerous()\n File \"./x.py\", line 5, in do_something_dangerous\n raise Exception(\"something bad happens here\")\n Exception: something bad happens here\n \n ========== sourcecode ==========\n -------------------------\n -- ./x.py: my_function --\n -------------------------\n 7 @logex.log(view_source=True, reraise=False)\n 8 def my_function():\n 9 x = 1\n 10--> do_something_dangerous()\n ...\n \n Locals when executing line 10:\n * x: 1\n \n ------------------------------------\n -- ./x.py: do_something_dangerous --\n ------------------------------------\n 4 def do_something_dangerous():\n 5--> raise Exception(\"something bad happens here\")\n \n ================================\n\nWe have several differences here:\n\n- the exception is not reraised, this is probably not always desired, but makes\n some nicer output here ;)\n- a view of the sourcecode for each function in the traceback\n- a list of the current values for local variables, if present", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/insecure/logex", "keywords": "debug log unhandled exception thread dbus D-Bus", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "logex", "package_url": "https://pypi.org/project/logex/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/logex/", "project_urls": { "Homepage": "https://github.com/insecure/logex" }, "release_url": "https://pypi.org/project/logex/2.1.1/", "requires_dist": null, "requires_python": null, "summary": "Easily log uncaught exceptions in D-Bus, thread and other functions.", "version": "2.1.1" }, "last_serial": 1530155, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "d0849555ca982dd991b6d93248558419", "sha256": "29bd753893f78ad975766f100ea6c5db3a78d1778ef36a783831ec54f1b0320e" }, "downloads": -1, "filename": "logex-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d0849555ca982dd991b6d93248558419", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4096, "upload_time": "2014-12-05T22:58:14", "url": "https://files.pythonhosted.org/packages/48/ff/4632c31ed4d86f0a7b088b581c2beeaa9009ef411dda90b50b168ee63510/logex-1.0.0.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "ff434fc3f42cd615629f2fe05f2370ae", "sha256": "8e34d8dbcefad1123d74c2e5fdee38124996e8fd91ab30fdd5927f02adde1d4e" }, "downloads": -1, "filename": "logex-2.0.0.tar.gz", "has_sig": false, "md5_digest": "ff434fc3f42cd615629f2fe05f2370ae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10628, "upload_time": "2014-12-11T21:52:27", "url": "https://files.pythonhosted.org/packages/57/14/feebef0bca411b513e3e4efe874333b73dfdf988a51e0d82237934229a66/logex-2.0.0.tar.gz" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "d4ca1ef7268ecba235ba842dd3dfa6eb", "sha256": "bd9ef7062cf906cd1ef8435b1949dd1c71b584c7cf1013dd9960b0b83f2545cd" }, "downloads": -1, "filename": "logex-2.1.0.tar.gz", "has_sig": false, "md5_digest": "d4ca1ef7268ecba235ba842dd3dfa6eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12267, "upload_time": "2014-12-14T21:01:19", "url": "https://files.pythonhosted.org/packages/62/b7/7b089aa16d7725dcc9e2dea3270d6b1c7d5a653ca48f10084fb2089f1e76/logex-2.1.0.tar.gz" } ], "2.1.1": [ { "comment_text": "", "digests": { "md5": "bfa08e611dc4005b3870107125787a3c", "sha256": "4c21fc51357da01f6bc1c993957a22496cf54d6e8e085bc7cc14e7d84fd64437" }, "downloads": -1, "filename": "logex-2.1.1.tar.gz", "has_sig": false, "md5_digest": "bfa08e611dc4005b3870107125787a3c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12342, "upload_time": "2015-05-02T06:19:32", "url": "https://files.pythonhosted.org/packages/b9/fa/3b94f021430ca231014de278df361b871fb99ce8687eab99496b6ed47ebf/logex-2.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bfa08e611dc4005b3870107125787a3c", "sha256": "4c21fc51357da01f6bc1c993957a22496cf54d6e8e085bc7cc14e7d84fd64437" }, "downloads": -1, "filename": "logex-2.1.1.tar.gz", "has_sig": false, "md5_digest": "bfa08e611dc4005b3870107125787a3c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12342, "upload_time": "2015-05-02T06:19:32", "url": "https://files.pythonhosted.org/packages/b9/fa/3b94f021430ca231014de278df361b871fb99ce8687eab99496b6ed47ebf/logex-2.1.1.tar.gz" } ] }