{ "info": { "author": "Chris (Someguy123) @ Privex", "author_email": "chris@privex.io", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# Python Log Helper\n\n[![PyPi Version](https://img.shields.io/pypi/v/privex-loghelper.svg)](https://pypi.org/project/privex-loghelper/)\n![License Button](https://img.shields.io/pypi/l/privex-loghelper) ![PyPI - Downloads](https://img.shields.io/pypi/dm/privex-loghelper)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/privex-loghelper) \n![GitHub last commit](https://img.shields.io/github/last-commit/Privex/python-loghelper)\n\n**Python Log Helper** is a small class designed to simplify the use of the built-in Python Logging Module.\n\nIt has no dependencies, and should be compatible with most versions of Python 2.x and 3.x (though we still recommend a minimum of 3.4).\n\nIt was originally created by [Chris (Someguy123)](https://github.com/Someguy123) for use in personal Python projects, \nas well as for use in projects developed at [Privex Inc.](https://github.com/Privex)\n\n**If this project has helped you, consider [grabbing a VPS or Dedicated Server from Privex](https://www.privex.io) - prices start at as little as 8 USD/mo (we take cryptocurrency!)**\n\n# License\n\n**Python Log Helper** was created by [Privex Inc. of Belize City](https://www.privex.io), and licensed under the X11/MIT License. \nSee the file [LICENSE](https://github.com/Privex/python-loghelper/blob/master/LICENSE) for the license text.\n\n**TL;DR; license:**\n\nWe offer no warranty. You can copy it, modify it, use it in projects with a different license, and even in commercial (paid for) software.\n\nThe most important rule is - you **MUST** keep the original license text visible (see `LICENSE`) in any copies.\n\n# Contributing\n\nWe're happy to accept pull requests, no matter how small.\n\nPlease make sure any changes you make meet these basic requirements:\n\n - No additional dependencies. We want LogHelper to be lightweight and painless to install.\n - Any code taken from other projects should be compatible with the MIT License\n - This is a new project, and as such, supporting Python versions prior to 3.4 is very low priority.\n - However, we're happy to accept PRs to improve compatibility with older versions of Python, as long as it doesn't:\n - drastically increase the complexity of the code\n - OR cause problems for those on newer versions of Python.\n\n# Installation\n\n### Download and install from PyPi using pip\n\n**Python 3**\n\n```sh\npip3 install privex-loghelper\n```\n\n**Python 2**\n\n```sh\npip install privex-loghelper\n```\n\n### (Alternative) Manual install from Git\n\n**Option 1 - Use pip to install straight from Github**\n\n```sh\npip3 install git+https://github.com/Privex/python-loghelper\n```\n\n**Option 2 - Clone and install manually**\n\n```bash\n# Clone the repository from Github\ngit clone https://github.com/Privex/python-loghelper\ncd python-loghelper\n\n# RECOMMENDED INSTALL METHOD\n# Use pip to install the source code\npip3 install .\n\n# ALTERNATIVE INSTALL METHOD\n# If you don't have pip, or have issues with installing using it, then you can use setuptools instead.\npython3 setup.py install\n```\n\n# Usage\n\nThe code is very well documented, you can find out all usage documentation in [LogHelper.py](https://github.com/Privex/python-loghelper/blob/master/privex/loghelper/LogHelper.py).\n\nAll functions are type annotated, with detailed pydoc block comments. If you're using a Python optimised IDE such as [PyCharm](https://www.jetbrains.com/pycharm/) it should\noffer code completion and help when using the package.\n\n![Screenshot of PyCharm code completion and docs](https://i.imgur.com/T2a0aTm.png)\n\n### Basic usage\n\nThe most basic usage is to simply initialise the class with no parameters, and attach a \nfile handler to send log output to a file.\n\n```python\n# Import the class\nfrom privex.loghelper import LogHelper\n# The first param is logger_name - a hierarchical dot-separated name to organise loggers.\n# If it's not specified, or is None, it will use the root logger (which will affect some\n# third-party packages that don't have their own logging settings)\nlh = LogHelper('mylogger')\n# Log to a file called test.log in the current directory\nlh.add_file_handler('test.log')\n# Grab the logger instance\nlog = lh.get_logger()\n# Now let's log 'hello world' to the file.\nlog.info('hello world')\n```\n\nAfter running the above, `test.log` should contain:\n\n```\n2018-12-05 22:05:18,915 root INFO hello world\n```\n\n### Copying your logging config to other logger names\n\nThird party packages often use their own logging instance names. To make it easy for you to copy your settings\nto other instances, you can use the `copy_logger(name)` method.\n\n```python\n# Set up logging for your app, log anything >=INFO\nlh = LogHelper('myapp', handler_level=logging.INFO)\n# Log to a file called test.log in the current directory (note: absolute path is better)\nlh.add_file_handler('test.log')\n# Now copy your logging level, handlers, and formatting to the logger privex.jsonrpc\nlh.copy_logger('privex.jsonrpc')\n# You can specify multiple logger names as positional arguments. All specified loggers will\n# have their handlers replaced with yours, and have their logging level set to match.\nlh.copy_logger('example.app', 'otherexample')\n```\n\nAfter copying your settings onto a named logger, all logging using that logger should use your specified handlers,\nand your log level.\n\nThis covers modules that access the logger via `logging.getLogger('loggername')`, as well as via Python Logging wrappers \nsuch as privex-loghelper.\n\n### Splitting error and debug logs into different files\n\nSomething that can make it easier to sift through logs, is to split your normal debug logs from warnings and errors.\n\nUsing the standard `logging` module, this could take 10 lines of code, and is highly repetitive.\n\nWith the Python Log Helper, it's just a few lines.\n\n```python\n# Import the class\nfrom privex.loghelper import LogHelper\n# Import logging to be able to specify the verbosity levels\nimport logging\n\n# The global level (kwarg `level`) defaults to DEBUG, but the default handler level is only INFO.\n# You can specify handler_level to change that. \n# To help prevent conflicts from other python packages which use the root ('') logger, you should set a custom\n# logger name.\nlh = LogHelper(logger_name='my_app', handler_level=logging.DEBUG)\n\n# Log messages that are DEBUG (default handler and global logging level) or higher to `debug.log`\nlh.add_file_handler('debug.log')\n\n# Log only WARNING or above to `error.log`\nlh.add_file_handler('error.log', level=logging.WARNING)\n\n# Grab the logger instance\nlog = lh.get_logger()\n\n# To test that logs are being sent to the correct files, let's try an `info`, a `warning` and an `error` log message.\nlog.info('something normal is happening')\nlog.warning('something strange is happening')\nlog.error('something VERY BAD is happening')\n\n```\n\nAfter running the above Python script, you should see the following log files:\n\n**debug.log**\n\n```\n2018-12-05 22:10:25,253 root INFO something normal is happening\n2018-12-05 22:10:25,254 root WARNING something strange is happening\n2018-12-05 22:10:25,256 root ERROR something VERY BAD is happening\n```\n\n**error.log**\n\n```\n2018-12-05 22:10:25,254 root WARNING something strange is happening\n2018-12-05 22:10:25,256 root ERROR something VERY BAD is happening\n```\n\nAs you can see, the `debug.log` saved all of the messages, while `error.log` only saved the warning and the error.\n\n### Log Rotation\n\nYou can also have painless log rotation, without the need for something like `logrotated`.\n\nThe LogHelper class has a function `add_timed_file_handler` which wraps `logging.handler.TimedRotatingFileHandler`.\n\nSimply specify the type of interval (`when`) to rotate with, how often it should rotate (`interval`), and how many intervals you\nwould like to keep before deleting older ones (`backups`). Set `backups` to 0 if you don't want it to delete older logs.\n\nFor more information on `interval`, `when` and `backups`, \nsee [the official logging docs](https://docs.python.org/3.7/library/logging.handlers.html#timedrotatingfilehandler)\n\nBy default, logs are rotated once (interval=1) per day (when='D'), and removed after 14 days (backups=14).\n\n```python\n# Import the class\nfrom privex.loghelper import LogHelper\n# Using sleep to simulate time passing\nfrom time import sleep\nlh = LogHelper()\n# Log to a file called test.log in the current directory\n# Rotate the log every minute, and only keep up to 60 minutes of logs\nlh.add_timed_file_handler('test.log', when='M', interval=1, backups=60)\n# Grab the logger instance\nlog = lh.get_logger()\n# Now let's log 'hello world' to the file.\nlog.info('hello world')\nlog.info('hello world 2')\nsleep(60)\nlog.info('hello world 3')\n```\n\nWe can now see it's generated two timestamped logs, since the interval was set to 1 minute.\n\n```bash\n$ ls -l\n -rw-r--r-- 1 user users 58 5 Dec 22:58 test.log.2018-12-05_22-58\n -rw-r--r-- 1 user users 58 5 Dec 22:59 test.log.2018-12-05_22-59\n\n$ cat test.log.2018-12-05_22-58\n 2018-12-05 22:58:24,600 root INFO hello world\n 2018-12-05 22:58:24,743 root INFO hello world 2\n\n$ cat test.log.2018-12-05_22-59\n 2018-12-05 22:59:25,512 root INFO hello world 3\n```\n\n# Thanks for reading!\n\n**If this project has helped you, consider [grabbing a VPS or Dedicated Server from Privex](https://www.privex.io) - prices start at as little as US$8/mo (we take cryptocurrency!)**\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Privex/python-loghelper", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "privex-loghelper", "package_url": "https://pypi.org/project/privex-loghelper/", "platform": "", "project_url": "https://pypi.org/project/privex-loghelper/", "project_urls": { "Homepage": "https://github.com/Privex/python-loghelper" }, "release_url": "https://pypi.org/project/privex-loghelper/1.0.6/", "requires_dist": null, "requires_python": "", "summary": "Small dependency-free class to make logging easier", "version": "1.0.6" }, "last_serial": 5877673, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "e6392c23521b917f2e751ecedb9be415", "sha256": "cb8e8b51761fec4f785de6003ef8219460e96d55dd5037ed7b55f84554c9ec82" }, "downloads": -1, "filename": "privex_loghelper-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "e6392c23521b917f2e751ecedb9be415", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9507, "upload_time": "2018-12-06T00:19:10", "url": "https://files.pythonhosted.org/packages/a9/51/5944d86d5051cf7ff0f2b95572c1a794e3e440cd76892a680092ce7df7ab/privex_loghelper-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6b9ffd2c7e719916e0b791cde81836e9", "sha256": "4437c5873b704ddb1693e56122fceb3ec25ab38203dae304c380ede9bc6fc6dd" }, "downloads": -1, "filename": "privex_loghelper-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6b9ffd2c7e719916e0b791cde81836e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7663, "upload_time": "2018-12-06T00:19:12", "url": "https://files.pythonhosted.org/packages/d4/4c/714bae1197442a6582c80d0b925bc3789c71effee133aac88e00bcba8ef9/privex_loghelper-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "16c72bfd1a6f082dfe022cd25d6cee8e", "sha256": "387d0cea1e856eb1c21e1bf50a849995473035613b435079e8de776c7fcbf07c" }, "downloads": -1, "filename": "privex_loghelper-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "16c72bfd1a6f082dfe022cd25d6cee8e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9607, "upload_time": "2018-12-06T00:38:27", "url": "https://files.pythonhosted.org/packages/59/31/2d070e93de78719bd6437d87853543cc78c1cae352c61906ed89de428b40/privex_loghelper-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6cee872460dd44e3ef4c6ddbc1f8720f", "sha256": "6eec12923a5b50c525349df6cec22599b2b50158be8cbaaeacc7f4dab4361d2a" }, "downloads": -1, "filename": "privex_loghelper-1.0.1.tar.gz", "has_sig": false, "md5_digest": "6cee872460dd44e3ef4c6ddbc1f8720f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7824, "upload_time": "2018-12-06T00:38:29", "url": "https://files.pythonhosted.org/packages/e2/42/ee4f7611108472cfa7527b8903baa2508042c73fe189812a5e7be1530cca/privex_loghelper-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "c159dfd1a4da42365fbbda8a10fe97ae", "sha256": "0cf9edfdd5e8e99f7e848fb62c937c38aff2b6f98052633225cdbb155297eac7" }, "downloads": -1, "filename": "privex_loghelper-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c159dfd1a4da42365fbbda8a10fe97ae", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10590, "upload_time": "2019-03-18T00:43:10", "url": "https://files.pythonhosted.org/packages/58/a0/06eefee5497daa5bff66058db8cd33fc8e63341f6f57f7358af4d6b7d357/privex_loghelper-1.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ea3026fcf7689d738e7936168ea0b741", "sha256": "526d1029ad1f30817dcf7adb9bce7fdd25aae374c548890b493a615ea0308c4f" }, "downloads": -1, "filename": "privex_loghelper-1.0.2.tar.gz", "has_sig": false, "md5_digest": "ea3026fcf7689d738e7936168ea0b741", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8676, "upload_time": "2019-03-18T00:43:12", "url": "https://files.pythonhosted.org/packages/fd/4a/880831892c0aa31571afcd015b3dd232bf3cb376ab97c60b393048a91ae0/privex_loghelper-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "384b5908465f2345a01ae49f25bc9301", "sha256": "8e46506e53a140d02e92a99af64b71254dcfe4a0d530909aaf44f92899b0aacc" }, "downloads": -1, "filename": "privex_loghelper-1.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "384b5908465f2345a01ae49f25bc9301", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11360, "upload_time": "2019-03-19T17:47:04", "url": "https://files.pythonhosted.org/packages/2a/9a/b15465210c9dbc074162766ba1b9a835fc06ae83b70beef00567c61eeaf8/privex_loghelper-1.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a81fc97ed8678c55abdf5438046f9c50", "sha256": "370debb69f3cf85c84bb4efd951c41e03ac9f4947b20622fe01d931798ac4dd8" }, "downloads": -1, "filename": "privex_loghelper-1.0.3.tar.gz", "has_sig": false, "md5_digest": "a81fc97ed8678c55abdf5438046f9c50", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9497, "upload_time": "2019-03-19T17:47:07", "url": "https://files.pythonhosted.org/packages/25/9b/6a247c07f1a5740950aad580fbca310dd4172538635ca90cf29ba1ef402b/privex_loghelper-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "8704454e7bea6bda51ea3817d5f2cd12", "sha256": "3b598c9d9e6e74a0890a48eb13d4e9ca04f5d1bf0c8da8021620b1eaa0aacca3" }, "downloads": -1, "filename": "privex_loghelper-1.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "8704454e7bea6bda51ea3817d5f2cd12", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11451, "upload_time": "2019-03-27T03:26:21", "url": "https://files.pythonhosted.org/packages/82/28/c9d3a835a7291c3ae17bdbc476315e0b1826788721c8839b3a3909062e40/privex_loghelper-1.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c5256ac47a188f5d5c75deda07e3d060", "sha256": "31319ad0c46df1a6319fe70e387f06fe1a05d13d9def149e36f6e2d435ae6979" }, "downloads": -1, "filename": "privex_loghelper-1.0.4.tar.gz", "has_sig": false, "md5_digest": "c5256ac47a188f5d5c75deda07e3d060", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9654, "upload_time": "2019-03-27T03:26:25", "url": "https://files.pythonhosted.org/packages/20/ab/5b0a47dea656ee8963d84c1f2a1510e2db5fb3d2980aca8481f6290b9f7e/privex_loghelper-1.0.4.tar.gz" } ], "1.0.5": [ { "comment_text": "", "digests": { "md5": "6b77fd7f440478cea253cb69fd45d4c6", "sha256": "3b9475382eb0f59a8bcf485236041b7d9554eb6cff76ffe9a806d739d9da4dd2" }, "downloads": -1, "filename": "privex_loghelper-1.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "6b77fd7f440478cea253cb69fd45d4c6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11529, "upload_time": "2019-07-05T02:56:06", "url": "https://files.pythonhosted.org/packages/3f/46/2c948158d111cc15e7ba7df092647d802eca2c7b5f8027a3ad8f0a2dc179/privex_loghelper-1.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e297438263645749f5ececa5900b54eb", "sha256": "710190ab933c98ba218f3693354cbb192f53e1a16e7f408d435767e30510ebd8" }, "downloads": -1, "filename": "privex_loghelper-1.0.5.tar.gz", "has_sig": false, "md5_digest": "e297438263645749f5ececa5900b54eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9724, "upload_time": "2019-07-05T02:56:12", "url": "https://files.pythonhosted.org/packages/5f/96/436d2fb233dceb41b56e6dde5db2b8080029f221811dfe40770300a545d6/privex_loghelper-1.0.5.tar.gz" } ], "1.0.6": [ { "comment_text": "", "digests": { "md5": "35ac8b51e9d3d9ae8b3e82f818d1c136", "sha256": "db9c63fa630746263d35fd10e086ea2230d87628ee802b1856a94dd525fd2a24" }, "downloads": -1, "filename": "privex_loghelper-1.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "35ac8b51e9d3d9ae8b3e82f818d1c136", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11745, "upload_time": "2019-09-24T05:42:28", "url": "https://files.pythonhosted.org/packages/00/01/858f4368893195c16ce70a1945245dce03783ff238b2a77970dff2826f12/privex_loghelper-1.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "63f295372fb798b924b2aa18e3e82753", "sha256": "f783fb848e281d639f75ae240d0cf048f0ae2c860157e3dad2833b2392230f47" }, "downloads": -1, "filename": "privex_loghelper-1.0.6.tar.gz", "has_sig": false, "md5_digest": "63f295372fb798b924b2aa18e3e82753", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10004, "upload_time": "2019-09-24T05:42:30", "url": "https://files.pythonhosted.org/packages/82/0a/01acffad0d39165b54e48fdb37ae24187862cac7a357d0e695743c02bbe6/privex_loghelper-1.0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "35ac8b51e9d3d9ae8b3e82f818d1c136", "sha256": "db9c63fa630746263d35fd10e086ea2230d87628ee802b1856a94dd525fd2a24" }, "downloads": -1, "filename": "privex_loghelper-1.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "35ac8b51e9d3d9ae8b3e82f818d1c136", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11745, "upload_time": "2019-09-24T05:42:28", "url": "https://files.pythonhosted.org/packages/00/01/858f4368893195c16ce70a1945245dce03783ff238b2a77970dff2826f12/privex_loghelper-1.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "63f295372fb798b924b2aa18e3e82753", "sha256": "f783fb848e281d639f75ae240d0cf048f0ae2c860157e3dad2833b2392230f47" }, "downloads": -1, "filename": "privex_loghelper-1.0.6.tar.gz", "has_sig": false, "md5_digest": "63f295372fb798b924b2aa18e3e82753", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10004, "upload_time": "2019-09-24T05:42:30", "url": "https://files.pythonhosted.org/packages/82/0a/01acffad0d39165b54e48fdb37ae24187862cac7a357d0e695743c02bbe6/privex_loghelper-1.0.6.tar.gz" } ] }