{ "info": { "author": "Eduardo Alonso", "author_email": "eduardo.alonsogarcia@telefonica.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "# pylogops\nReally simple json formatter for python projects.\n\n### Status\n[![Build Status](https://travis-ci.org/telefonicaid/pylogops.svg)](https://github.com/telefonicaid/pylogops)\n\n## Installation\n\n```bash\npip install pylogps\n```\n\nif you want use with python2.6 you must install the backport ordereddict as well:\n\n```bash\npip install ordereddict\n```\n\n\n## Basic usage\nYou will have to specify the formatter *JsonFormatter* in any handler that you use in standar python logging:\n\n```py\nimport logging\nimport time\nfrom pylogops.logger import JsonFormatter\n\nfile_handler = logging.FileHandler('/tmp/my_log.log', encoding='UTF-8')\nfile_handler.setFormatter(JsonFormatter(converter=time.localtime))\nlogging.basicConfig()\nlogger = logging.getLogger(\"my_logger\")\nlogger.addHandler(file_handler)\nlogger.setLevel(logging.INFO)\nlogger.info(\"Msg\")\n\n```\nthis will produce a log in json:\n```json\n{\"time\": \"2015-12-09T17:46:01.160Z\", \"lvl\": \"INFO\", \"corr\": null, \"trans\": null, \"op\": null, \"comp\": \"\", \"msg\": \"Msg\"}\n```\n\n**pylogps** by default generate all the upper fields in json output, but you can select to remove null fields:\n\n```py\nimport logging\nimport time\nfrom pylogops.logger import JsonFormatter\n\nfile_handler = logging.FileHandler('/tmp/my_log.log', encoding='UTF-8')\nfile_handler.setFormatter(JsonFormatter(remove_blanks=True))\nlogging.basicConfig()\nlogger = logging.getLogger(\"my_logger\")\nlogger.addHandler(file_handler)\nlogger.setLevel(logging.INFO)\nlogger.info(\"Msg\")\n\n\n```\nthis will produce a log in json:\n```json\n{\"time\": \"2015-12-09T16:57:00.784Z\", \"lvl\": \"INFO\", \"comp\": \"\", \"msg\": \"Msg\"}\n```\n\nYou can configure the formatter in any way provided by python logging library, e.g (dictConfig, fileConfig, \u2026). You can check unit tests directory for some example.\n\n## Advanced usage\n\n### Context support\n\nPylogps includes a filter and a local_context to support using a context holding information about a correlator (corr), transaction (trans) and operation (op).\nIf you include the values using local_context, those fields will be available in formatter. You need to add a Filter:\n\n```py\nimport logging\nimport time\nfrom pylogops.logger import TrackingFilter, JsonFormatter\n\nfile_handler = logging.FileHandler('/tmp/my_log.log', encoding='UTF-8')\nfile_handler.addFilter(TrackingFilter())\nfile_handler.setFormatter(JsonFormatter(remove_blanks=True))\nlogging.basicConfig()\nlogger = logging.getLogger(\"my_logger\")\nlogger.addHandler(file_handler)\nlogger.setLevel(logging.INFO)\n\n\nfrom pylogops import local_context\nlocal_context.transaction_id = \"trans\"\nlocal_context.correlator_id = \"corr\"\nlocal_context.op_type = \"op\"\n\nlogger.info(\"Msg\")\n```\nThis will produce the json log:\n```json\n{\"time\": \"2015-12-10T15:23:52.117Z\", \"lvl\": \"INFO\", \"corr\": \"corr\", \"trans\": \"trans\", \"op\": \"op\", \"comp\": \"\", \"msg\": \"Msg\"}\n```\n\nlocal_context is a thread.local() that is shared in current thread for all modules; typically you will include the values in a middleware or some kind of transversal module.\n\n\n### Customizing json fields\n\nYou can specify the fields for output in json in this way:\n```py\nimport logging\nimport time\nfrom pylogops.logger import JsonFormatter\n\nfile_handler = logging.FileHandler('/tmp/my_log.log', encoding='UTF-8')\nfile_handler.setFormatter(JsonFormatter(keys_fmt=[('lvl', 'levelname'), ('msg', 'message')]))\nlogging.basicConfig()\nlogger = logging.getLogger(\"my_logger\")\nlogger.addHandler(file_handler)\nlogger.setLevel(logging.INFO)\nlogger.info(\"Msg\")\n\n\n```\nthis will produce a log in json:\n\n```json\n{\"lvl\": \"INFO\", \"msg\": \"Msg\"}\n```\n\n\n## License\n\nCopyright 2014, 2015 [Telefonica Investigaci\u00f3n y Desarrollo, S.A.U](http://www.tid.es)\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.", "description_content_type": null, "docs_url": "https://pythonhosted.org/pylogops/", "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/telefonicaid/pylogops", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "pylogops", "package_url": "https://pypi.org/project/pylogops/", "platform": "OS Independent", "project_url": "https://pypi.org/project/pylogops/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/telefonicaid/pylogops" }, "release_url": "https://pypi.org/project/pylogops/1.1.0/", "requires_dist": null, "requires_python": null, "summary": "A simple json formatter for python logging.", "version": "1.1.0" }, "last_serial": 2437854, "releases": { "1.0.2": [ { "comment_text": "", "digests": { "md5": "9d76584051940d580e392b9b9da41846", "sha256": "616c4545bea89fe66550aa3995a996a6c9317d6c54c6ea3f55b50b3a1ff84904" }, "downloads": -1, "filename": "pylogops-1.0.2.tar.gz", "has_sig": false, "md5_digest": "9d76584051940d580e392b9b9da41846", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5158, "upload_time": "2015-12-10T16:44:22", "url": "https://files.pythonhosted.org/packages/60/59/88b5c8065429af13b1d8c291485b21fb24413777dfb99a29cf4d08af10b6/pylogops-1.0.2.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "951a23b8a807fa0c1e4124e23b28d8d0", "sha256": "81089992a5cc074f14a743f53d4499edcb1a6cf50c16f3b12aeef24a323b051c" }, "downloads": -1, "filename": "pylogops-1.1.0.tar.gz", "has_sig": false, "md5_digest": "951a23b8a807fa0c1e4124e23b28d8d0", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 5178, "upload_time": "2016-11-02T14:45:21", "url": "https://files.pythonhosted.org/packages/00/5c/74a5d6c9404f6bc4c36a76e1b670a89fc9f62e25d1b30d9c7291eb6b841d/pylogops-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "951a23b8a807fa0c1e4124e23b28d8d0", "sha256": "81089992a5cc074f14a743f53d4499edcb1a6cf50c16f3b12aeef24a323b051c" }, "downloads": -1, "filename": "pylogops-1.1.0.tar.gz", "has_sig": false, "md5_digest": "951a23b8a807fa0c1e4124e23b28d8d0", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 5178, "upload_time": "2016-11-02T14:45:21", "url": "https://files.pythonhosted.org/packages/00/5c/74a5d6c9404f6bc4c36a76e1b670a89fc9f62e25d1b30d9c7291eb6b841d/pylogops-1.1.0.tar.gz" } ] }