{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# nk-logger\nA python logger that plays nice with Datadog. It outputs logs using a json formatter, sending `WARNING`, `ERROR`, and `CRITICAL` logs to `stderr` and `DEBUG` and `INFO` logs to `stdout`.\n\n# Basic Usage\n\npip install `git+https://github.com/NewKnowledge/nk-logger.git@#egg=nk_logger`. Typically, this is done by adding it to `requirements.txt` (pip) or `environment.yml` (conda). Make sure git is installed on the system or container.\n\nAt the top of each file that uses a logger, put:\n```\nfrom nk_logger import get_logger\nlogger = get_logger(__name__)\n```\n\nThen use like:\n```\nlogger.debug(\"this is content that usually won't be relevant\")\nlogger.info(\"this is important information\")\nlogger.info(f\"here is information about this variable: {var}\")\nlogger.warning(\"something might be wrong here\")\nlogger.error(\"oh no, an error!\")\nlogger.exception(\"oh no, an error! let's log the stack trace.\")\n```\nNote that `logger.exception(message)` is equivalent to `logger.error(message, exc_info=True)` and will automatically attach the exception information to the log.\n\nThe `nk_logger` module reads the `LOG_LEVEL` and `SERVICE_NAME` environment variables and does basic configuration on module import.\n\n# Configure\nThe `nk_logger` module has two config parameters: `level` and `prefix`. By default they are set by the environment variables `LOG_LEVEL` and `SERVICE_NAME` upon import if they are provided, otherwise they are set to 'INFO' and '' respectively. By default the root logger's log level is also set to the same `level`. The `config_logger` function allows you to optionally override those defaults and explicitly set the default `level`, `prefix`, or `root_log_level`. Specifying the `root_log_level` allows the root logger to have a different level than the loggers generated by `get_logger`; this is useful for exposing (or muting) third-party logs (e.g. from `kafka` or `requests`).\n\nAn example setup that would allow us to keep our own 'INFO' logs, but silence third-party logs below 'WARNING':\n\n```\nfrom nk_logger import config_logger\nconfig_logger(level=\"INFO\", root_log_level=\"WARNING\")\n```\n\nIf instead we are using a `config.py` file and want to keep third-party logs, the usage might look like:\n\n```\nfrom config import LOG_LEVEL, SERVICE_NAME\nfrom nk_logger import config_logger, get_logger\n\nconfig_logger(level=LOG_LEVEL, prefix=SERVICE_NAME)\nlogger = get_logger(__name__)\n```\n\n\n\n# Details\nUpon configuration, `nk_logger` creates two log handlers: `out_handler` and `err_handler`. `out_handler` writes logs to stdout and filters out logs above 'INFO'. `err_handler` writes logs to stderr and ignores logs below 'WARNING'. Both handlers are attached to the root logger and set to the given log `level`. Any new logger created is not given any handlers, so will pass its logs up to the root logger's handlers to be processed. Third-party logs are also sent to the root logger and processed by the same handlers as internal logs, so they are also json-formatted.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/NewKnowledge/nk-logger", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "nk-logger", "package_url": "https://pypi.org/project/nk-logger/", "platform": "", "project_url": "https://pypi.org/project/nk-logger/", "project_urls": { "Homepage": "https://github.com/NewKnowledge/nk-logger" }, "release_url": "https://pypi.org/project/nk-logger/1.1.0/", "requires_dist": null, "requires_python": "", "summary": "A python logger that plays nice with datadog", "version": "1.1.0" }, "last_serial": 4454640, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "fc8f21b55a93508aa6f50ce22f1317a3", "sha256": "a9367de1322607d9b4cbe40c2d44a4f92b58c75a4db4b98fd4eb39f0dc1dc1bb" }, "downloads": -1, "filename": "nk_logger-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fc8f21b55a93508aa6f50ce22f1317a3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1910, "upload_time": "2018-11-05T20:35:10", "url": "https://files.pythonhosted.org/packages/4e/fd/5622d40201793fe7d961ed1601bae54ae27c145e0adbf6e53e1650c7310a/nk_logger-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "306ba978ae8da649ba66d1a4354314b9", "sha256": "0b758b21fc973b5ddbab833133b65de23a9a13412b10e8dd3a5ad6fb1275e366" }, "downloads": -1, "filename": "nk_logger-1.0.0.tar.gz", "has_sig": false, "md5_digest": "306ba978ae8da649ba66d1a4354314b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1313, "upload_time": "2018-11-05T20:35:12", "url": "https://files.pythonhosted.org/packages/50/4f/9e4fe86094e419edc97655e42253e7a390a7cd6073d79e98f911f7468702/nk_logger-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "a7f56c3dfed28a6e335e0e4789834c1d", "sha256": "97a976d732c8b1959c802dd8a5da6441f6ee676aa7ec7c7a6f48796e46e22da9" }, "downloads": -1, "filename": "nk_logger-1.0.1.tar.gz", "has_sig": false, "md5_digest": "a7f56c3dfed28a6e335e0e4789834c1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1443, "upload_time": "2018-11-05T20:42:09", "url": "https://files.pythonhosted.org/packages/23/68/e07f4cfdf5e6f0a78f8480f3c17cd20378103f5463d3ef3ccaa6c725b389/nk_logger-1.0.1.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "f176c6794e610abb9565dc2abd994386", "sha256": "09efe981e66c679e61248ef6aeb635ef2013282b7382ca9d68f68e7d92821a6f" }, "downloads": -1, "filename": "nk_logger-1.1.0.tar.gz", "has_sig": false, "md5_digest": "f176c6794e610abb9565dc2abd994386", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3549, "upload_time": "2018-11-05T20:44:49", "url": "https://files.pythonhosted.org/packages/77/be/bdeb8222b2d847a99879a98f91330f1e409b3530edfdcee758baba3bf371/nk_logger-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f176c6794e610abb9565dc2abd994386", "sha256": "09efe981e66c679e61248ef6aeb635ef2013282b7382ca9d68f68e7d92821a6f" }, "downloads": -1, "filename": "nk_logger-1.1.0.tar.gz", "has_sig": false, "md5_digest": "f176c6794e610abb9565dc2abd994386", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3549, "upload_time": "2018-11-05T20:44:49", "url": "https://files.pythonhosted.org/packages/77/be/bdeb8222b2d847a99879a98f91330f1e409b3530edfdcee758baba3bf371/nk_logger-1.1.0.tar.gz" } ] }