{ "info": { "author": "Joel Smith", "author_email": "joel.pypi@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Simplog\n\nA simple, functional, opinionated logger for python\n\n## Motivation\n\nI generally only need to implement simple logging in my services. For the most part, I don't need anything especially fancy,\nbut I do need to stick to a consistent format, to help log analyzers do their job.\n\n## Requirements\n\nCurrently this requires python 3 to run (developed against 3.6, but should compile under most recent versions)\n\n## Usage\n\nThere are 3 main steps:\n\n1. Generate a loging function:\n `log = logger.make_logger(print)`\n2. Provide some input into logging function:\n `log(\"The program is exploding\", level='error', why='Value Error')`\n3. Observe the results:\n `2018-12-02T22:44:17.269137 level=error why=\"Value Error\" msg=\"The program is exploding\"`\n\nNote that only level and message are requird. Level, in addition, has a default value of `info`. All other values\nto be logged can be provided as keyword arguments (see above), which will be logged in `key=value` format. The current\nsystem time is always provided as well, to help order the events.\nIn addition, there are some configuration possible that will make themselves useful in certain situations.\n\n### Basic\n\nTypically, all I need is a print that goes to standard out. You can accomplish this via this approach:\n\n```python\nfrom logger import make_logger, refine_logger\nfrom uuid import uuid4\n\n# Generate a logger function\nmain_logger = make_logger()\n\nmain_logger(\"This is happening on the mainline\")\n# prints to standard out: 'dt level=info msg=\"This is happening on the mainline\"'\n\nctx_logger = refine_logger(main_logger, context=uuid4())\nctx_logger(\"A configured logger\")\n# prints to standard out: 'dt level=info context=\"ff088e2c-b127-4d8a-ba1d-347de59d302e\" msg=\"A configured logger\"'\n```\n\n### Advanced\n\nIf you need something more robust, then there are some configuration opportunities.\n\n#### Preconfigre log values\n\nIf you want to ensure that consistent values are always provided with the logger, you can refine the logger via the\n`refine_logger` method. This will return a new logger that always have the supplied arugments when called. Note that\nunder the hood, this is just a call to functool's `partial`\n\n```python\nlog = make_logger()\nrlog = refine_logger(log, confidence_level=\"100%\")\nrlog(\"Things are going well\")\n# Outputs: 2018-12-02T23:23:43.524875 level=info confidence_level=100% msg=\"Things are going well\"\n\n# These values is overwritable as well:\nrlog(\"Things aren't looking so great\", confidence_level=\"25%\")\n# Outputs: 2018-12-02T23:24:07.786726 level=info confidence_level=25% msg=\"Things aren't looking so great\"\n```\n\n#### Output to somewhere else\n\nThis project is meant to log to the console, but will accept any function that accepts a string as input.\n\n```python\n# Completely untested, but in theory this would work\nimport os\n\ndef make_filewriter_function(output_path):\n writer = open(output_path, 'a', 0) # Writing in unhuffered mode\n def write_fn(s):\n writer.write(s)\n\n def close_fn():\n os.close(writer)\n\n return write_fn, close_fn\n\nwrite_fn, close_fn = make_filewriter_function('/var/log/my-script-log.log')\nlog = logger.make_logger(write_fn)\n# ...\nclose_fn()\n```\n\n#### Change default labels\n\nIf you don't like `msg` and `level` you can easily switch these when making the logger\nIf you want to add a label for the time, you can do that too\n\n```python\ncustom_log = logger.make_logger(print, message_label='message', level_label='logLevel', time_label='app_time')\ncustom_log(\"Look at that!\")\n# outputs: app_time=2018-12-02T23:06:59.566174 logLevel=info message=\"Look at that!\"\n```\n\n#### Forcing quoting\n\nBy default, any value that does not have a space in it will be left unquoted, while any string that does have a space will be double-quoted\n(i.e. `\"Expect values like this\"`)\nIf you always make to make sure your values are quoted, you can do that by supplying `force_quote=True` in the make_logger constructor.\n\n#### Serialize non-standard values\n\nIf you have some class you want to log, you'll need to supply your own serializer. Once you have that, you can pass the serialize func\nusing the `to_string_func` parameter.\n\n## Development\n\nThis project uses pipenv to aid development. See https://pipenv.readthedocs.io/en/latest/ for usage.\n\n### Running tests\n\nThis project utilizes pytest for running unit tests. They can be run via:\n\n```sh\npipenv shell\ncd simplog\npython -m pytest\n```\n\n## TODOs\n\n1. Make a proper distributable\n2. Test & Optimize performance\n3. Suport custom character escapes?\n4. Add in support for mypy", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/JoelAtDeluxe/simplog/archive/v0.1.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/JoelAtDeluxe/simplog", "keywords": "logging,functional,splunk", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "simplog", "package_url": "https://pypi.org/project/simplog/", "platform": "", "project_url": "https://pypi.org/project/simplog/", "project_urls": { "Download": "https://github.com/JoelAtDeluxe/simplog/archive/v0.1.0.tar.gz", "Homepage": "https://github.com/JoelAtDeluxe/simplog" }, "release_url": "https://pypi.org/project/simplog/0.1.0/", "requires_dist": null, "requires_python": "", "summary": "A simple, functional, opinionated logger for python", "version": "0.1.0" }, "last_serial": 5273626, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d3e4bdcc357c4646cd98c5c773779b07", "sha256": "216779627b7db6e84b5b5c150d283239d713e38e9e060067aba34183cd892e12" }, "downloads": -1, "filename": "simplog-0.0.1.tar.gz", "has_sig": false, "md5_digest": "d3e4bdcc357c4646cd98c5c773779b07", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3172, "upload_time": "2019-05-15T16:20:04", "url": "https://files.pythonhosted.org/packages/da/53/577c93206e8fcebe75e6e03f9899d8aca5149f4600a2f3aee9f4f2a85d9c/simplog-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "c20d9ed4d7e32e563679aa6ec32ca8ea", "sha256": "2a4c42fd301a3577979318b678951bd4a3eab05100b27a357392e9d72e004903" }, "downloads": -1, "filename": "simplog-0.0.2.tar.gz", "has_sig": false, "md5_digest": "c20d9ed4d7e32e563679aa6ec32ca8ea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5038, "upload_time": "2019-05-15T16:30:41", "url": "https://files.pythonhosted.org/packages/23/7d/de9c7566e9083c6674a33220a56d05de365fc02180793b53b05461c1fbdb/simplog-0.0.2.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "870246f561b09debe55534d2a5b31fbc", "sha256": "6e705b432b2fdd1fa6f5b12b8c9e880b51d47e73a02b808783f8e2458d0dd34b" }, "downloads": -1, "filename": "simplog-0.1.0.tar.gz", "has_sig": false, "md5_digest": "870246f561b09debe55534d2a5b31fbc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5788, "upload_time": "2019-05-15T17:51:19", "url": "https://files.pythonhosted.org/packages/f9/c7/499d8e4735cac02eae2e86104258dda6467e57ec03a6dd58568775665838/simplog-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "870246f561b09debe55534d2a5b31fbc", "sha256": "6e705b432b2fdd1fa6f5b12b8c9e880b51d47e73a02b808783f8e2458d0dd34b" }, "downloads": -1, "filename": "simplog-0.1.0.tar.gz", "has_sig": false, "md5_digest": "870246f561b09debe55534d2a5b31fbc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5788, "upload_time": "2019-05-15T17:51:19", "url": "https://files.pythonhosted.org/packages/f9/c7/499d8e4735cac02eae2e86104258dda6467e57ec03a6dd58568775665838/simplog-0.1.0.tar.gz" } ] }