{ "info": { "author": "Jakob R\u00f6\u00dfler", "author_email": "roessler@sighalt.de", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: System :: Logging" ], "description": "Logdecorator\n============\n\n|Downloads|\n\nMove logging code out of your business logic with python decorators.\n\nLogging is a nice tool in your toolbox for tracing bugs and getting a\nbetter sense how your application is working in production. But if you\nare like me, you often omit logging code, so it will not hide business\nlogic or feature your code with complexity.\n\nFortunately pythons decorator now came to our rescue and provides us\nwith a nice library to add logging to our code without stealing\nreadability and understandability.\n\nIf you want to know more about the intentions behind logdecorator check\nout my `blog\npost `__.\n\nUpdate: logdecorator==2.0\n-------------------------\n\nThanks to all dependants :) I just released a new version of\nlogdecorator (2.0). You can read the changes at my\n`blog `__\nor in the `changelog `_.\n\nInstallation\n------------\n\nInstallation is as easy as it can get:\n\n.. code:: bash\n\n $ pip install logdecorator\n\nHow to use it\n-------------\n\nImagine a function ``download`` with no arguments and some download code\nin it.\n\n.. code:: python\n\n def download():\n # some download code\n pass\n\n if __name__ == \"__main__\":\n download()\n\n\nSay you are going to launch your new tool but want to add some logging\nbefore releasing the kraken. Your code will probably look something like\nthe following:\n\n.. code:: python\n\n import logging\n from .exceptions import MyException1, MyException2\n\n logger = logging.getLogger(__name__)\n\n\n def download():\n logger.debug(\"Start downloading\")\n # some download code\n logger.debug(\"Downloading finished successfully\")\n\n\n if __name__ == \"__main__\":\n try:\n download()\n except (MyException1, MyException2):\n logger.error(\"Error on downloading\")\n raise\n\nYou just added at least a couple lines of code which are eventually\nstumbling in your way when you are trying to understand your business\nlogic to find a bug. But what's even worse is, that you added an\nadditional indentation (try:... except: ...) just for the sake of\nlogging.\n\nWith logdecorator you can leave your code nearly as it was and reach the\nsame goals.\n\n.. code:: python\n\n import logging\n from logdecorator import log_on_start, log_on_end, log_on_error\n from .exceptions import MyException1, MyException2\n\n\n @log_on_start(logging.DEBUG, \"Start downloading\")\n @log_on_error(logging.ERROR, \"Error on downloading\",\n on_exceptions=(MyException1, MyException2),\n reraise=True)\n @log_on_end(logging.DEBUG, \"Downloading finished successfully\")\n def download():\n # some download code\n\n\n if __name__ == \"__main__\":\n download()\n\nMaybe the improvement to the previous snippet does not seem great for\nyou but if you actually fill in business logic into\n``# some download code`` it should become obvious :)\n\nWhat logdecorator can do for you\n--------------------------------\n\nDecorators\n~~~~~~~~~~\n\nlogdecorator provides four different built-in decorators:\n\n- log\\_on\\_start\n- log\\_on\\_end\n- log\\_on\\_error\n- log\\_exception\n\nwhose behaviour corresponds to their names.\n\nUse variables in messages\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe message, given to the decorator, is treated as a python format\nstring which takes the functions arguments as format arguments.\n\nSticking to the previous example one could write:\n\n.. code:: python\n\n\n import logging\n from logdecorator import log_on_start\n from .exceptions import MyException1, MyException2\n\n\n @log_on_start(logging.DEBUG, \"Start downloading '{url:s}'\")\n def download(url):\n # some download code\n\n\n if __name__ == \"__main__\":\n download(\"http://my.file.com/file.bin\")\n\nWhich results in the message\n``Start downloading 'http://my.file.com/file.bin'`` gets logged.\n\nArguments\n~~~~~~~~~\n\nlog\\_on\\_start\n^^^^^^^^^^^^^^\n\n**log\\_level** > The log level at which the message should be send\n\n**message** > The message to log\n\n**logger** *(optional)* > An alternative logger object. If no logger is\ngiven logdecorator creates a > logger object with the name of the module\nthe decorated function is in > (``decorated_function.__module__``) > >\nDefault: Creates a new logger with the name\n``decorated_function.__module__``\n\nlog\\_on\\_end\n^^^^^^^^^^^^\n\n**log\\_level** > The log level at which the message should be send\n\n**message** > The message to log\n\n**logger** *(optional)* > An alternative logger object. If no logger is\ngiven logdecorator creates a > logger object with the name of the module\nthe decorated function is in > (``decorated_function.__module__``) > >\nDefault: Creates a new logger with the name\n``decorated_function.__module__``\n\n**result\\_format\\_variable** *(optional)* > The variable name one can\nuse in the message to reference the result of the > decorated function >\ne.g. @log\\_on\\_end(DEBUG, \"Result was: {result!r}\") > > Default:\n\"result\"\n\nlog\\_on\\_error\n^^^^^^^^^^^^^^\n\n**log\\_level** > The log level at which the message should be send\n\n**message** > The message to log\n\n**logger** *(optional)* > An alternative logger object. If no logger is\ngiven logdecorator creates a > logger object with the name of the module\nthe decorated function is in > (``decorated_function.__module__``) > >\nDefault: Creates a new logger with the name\n``decorated_function.__module__``\n\n**on\\_exceptions** *(optional)* > A tuple containing exception classes\nor a single exception, which should get > caught and trigger the logging\nof the ``log_on_error`` decorator. > > Default: tuple() (No exceptions\nwill get caught)\n\n**reraise** *(optional)* > Controls if caught exceptions should get\nreraised after logging > > Default: False\n\n**exception\\_format\\_variable** *(optional)* > The variable name one can\nuse in the message to reference the caught exception > raised in the\ndecorated function > e.g. @log\\_on\\_error(ERROR, \"Error was: {e!r}\",\n...) > > Default: \"e\"\n\nlog\\_exception\n^^^^^^^^^^^^^^\n\n**log\\_level** > The log level at which the message should be send\n\n**message** > The message to log\n\n**logger** *(optional)* > An alternative logger object. If no logger is\ngiven logdecorator creates a > logger object with the name of the module\nthe decorated function is in > (``decorated_function.__module__``) > >\nDefault: Creates a new logger with the name\n``decorated_function.__module__``\n\n**on\\_exceptions** *(optional)* > A tuple containing exception classes\nor a single exception, which should get > caught and trigger the logging\nof the ``log_on_error`` decorator. > > Default: tuple() (No exceptions\nwill get caught)\n\n**reraise** *(optional)* > Controls if caught exceptions should get\nreraised after logging > > Default: False\n\n**exception\\_format\\_variable** *(optional)* > The variable name one can\nuse in the message to reference the caught exception > raised in the\ndecorated function > e.g. @log\\_on\\_error(ERROR, \"Error was: {e!r}\",\n...) > > Default: \"e\"\n\n.. |Downloads| image:: https://pepy.tech/badge/logdecorator\n :target: https://pepy.tech/project/logdecorator\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/sighalt/logdecorator", "keywords": "logging,decorators,clean code", "license": "", "maintainer": "", "maintainer_email": "", "name": "logdecorator", "package_url": "https://pypi.org/project/logdecorator/", "platform": "", "project_url": "https://pypi.org/project/logdecorator/", "project_urls": { "Homepage": "https://github.com/sighalt/logdecorator" }, "release_url": "https://pypi.org/project/logdecorator/2.1/", "requires_dist": null, "requires_python": "", "summary": "Move logging code out of your business logic with decorators", "version": "2.1" }, "last_serial": 4310418, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "61fcc1cc2ff1ef18ff743ad999f5c9dd", "sha256": "ac86da9defde3480359977ae0476dee838bfb224badb1dcc17ae3592191849a7" }, "downloads": -1, "filename": "logdecorator-1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "61fcc1cc2ff1ef18ff743ad999f5c9dd", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 4408, "upload_time": "2017-06-07T21:39:32", "url": "https://files.pythonhosted.org/packages/e2/af/78dd00570eff67880a9f793101617f935742e8a2aeef78166c0b010e2e9e/logdecorator-1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5b1e3090da36589d6131de93126301eb", "sha256": "f1ab2fabe42cf41a1e9e09f4df85c3aeb52b901ff06d0cbef5bbc79573c0f309" }, "downloads": -1, "filename": "logdecorator-1.0.tar.gz", "has_sig": false, "md5_digest": "5b1e3090da36589d6131de93126301eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4218, "upload_time": "2017-06-07T21:39:15", "url": "https://files.pythonhosted.org/packages/0c/83/2ad42d2cfa830a07f1e8b15cae48d68db4e3e15a7a25d5c53396fff35552/logdecorator-1.0.tar.gz" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "730e413bce4d4fd6b3c5630048134b13", "sha256": "7dbb752c5571a1fc4f760fd2052ef09418dc76007a85449acf825dd753061004" }, "downloads": -1, "filename": "logdecorator-2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "730e413bce4d4fd6b3c5630048134b13", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4440, "upload_time": "2018-09-09T12:17:17", "url": "https://files.pythonhosted.org/packages/f4/af/b14b34629224f595083b105e8c84011e3d264e42d7ff89c1d808640dca7a/logdecorator-2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "42dddd8e934bb0386318cac8ebcbefdf", "sha256": "906e3b33b8c48bb7b1e00b83656fda3c9b6c5b928050500a1a9421c445b1b067" }, "downloads": -1, "filename": "logdecorator-2.0.tar.gz", "has_sig": false, "md5_digest": "42dddd8e934bb0386318cac8ebcbefdf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4310, "upload_time": "2018-09-09T12:17:19", "url": "https://files.pythonhosted.org/packages/9e/41/7afb8a3fb27a2cb0c1bf85b95347015e21a9edb9206fda2ace3ae6b3807d/logdecorator-2.0.tar.gz" } ], "2.1": [ { "comment_text": "", "digests": { "md5": "cff80b9dd64d5a7a766767db900af544", "sha256": "324cff871cdd04a779cba14ca94e2912a3dbc43179053f0014c643c298b0f7f8" }, "downloads": -1, "filename": "logdecorator-2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "cff80b9dd64d5a7a766767db900af544", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8640, "upload_time": "2018-09-25T22:01:53", "url": "https://files.pythonhosted.org/packages/00/9c/5793a4be472732f0ad9db81d3fb2dcc6bda8f7fc04f31f5cc2f0c7f76254/logdecorator-2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a19ecfb7f97c9ad7a1dcb71a597c3018", "sha256": "993bb3f0ccaab169e3a7812d2be411cabb37d38f5d166a1b99b428daaa1dc797" }, "downloads": -1, "filename": "logdecorator-2.1.tar.gz", "has_sig": false, "md5_digest": "a19ecfb7f97c9ad7a1dcb71a597c3018", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5603, "upload_time": "2018-09-25T22:01:55", "url": "https://files.pythonhosted.org/packages/55/cf/9021026c01505d90d37230e2f50ce01414b317c597da1e6ffbf0b6151877/logdecorator-2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cff80b9dd64d5a7a766767db900af544", "sha256": "324cff871cdd04a779cba14ca94e2912a3dbc43179053f0014c643c298b0f7f8" }, "downloads": -1, "filename": "logdecorator-2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "cff80b9dd64d5a7a766767db900af544", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8640, "upload_time": "2018-09-25T22:01:53", "url": "https://files.pythonhosted.org/packages/00/9c/5793a4be472732f0ad9db81d3fb2dcc6bda8f7fc04f31f5cc2f0c7f76254/logdecorator-2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a19ecfb7f97c9ad7a1dcb71a597c3018", "sha256": "993bb3f0ccaab169e3a7812d2be411cabb37d38f5d166a1b99b428daaa1dc797" }, "downloads": -1, "filename": "logdecorator-2.1.tar.gz", "has_sig": false, "md5_digest": "a19ecfb7f97c9ad7a1dcb71a597c3018", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5603, "upload_time": "2018-09-25T22:01:55", "url": "https://files.pythonhosted.org/packages/55/cf/9021026c01505d90d37230e2f50ce01414b317c597da1e6ffbf0b6151877/logdecorator-2.1.tar.gz" } ] }