{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# Log Redactor\n\nRedacts data in python logs based on regex filters passed in by the user. \nThis will work with json logging formats as well and also with nested data in the `extra` argument. \n\n\n# Examples\n\n```python\nimport re\nimport logging\nimport logredactor\n\n# Create a logger\nlogger = logging.getLogger()\n# Add the redact filter to the logger with your custom filters\nredact_patterns = [re.compile(r'\\d+')]\n\n# if no `default_mask` is passed in, 4 asterisks will be used\nlogger.addFilter(logredactor.RedactingFilter(redact_patterns, default_mask='xx'))\n\nlogger.warning(\"This is a test 123...\")\n# Output: This is a test xx...\n```\n\nPython only applies the filter on that logger, so any other files using logging will not get the filter applied. To have this filter applied to all loggers do the following\n```python\nimport re\nimport logging\nimport logredactor\nfrom pythonjsonlogger import jsonlogger\n\n# Create a pattern to hide api key in url. This uses a _Positive Lookbehind_\nredact_patterns = [re.compile(r'(?<=api_key=)[\\w-]+')]\n\n# Override the logging handler that you want redacted\nclass RedactStreamHandler(logging.StreamHandler):\n def __init__(self, *args, **kwargs):\n logging.StreamHandler.__init__(self, *args, **kwargs)\n self.addFilter(logredactor.RedactingFilter(redact_patterns))\n\nroot_logger = logging.getLogger()\n\nsys_stream = RedactStreamHandler()\n# Also set the formatter to use json, this is optional and all nested keys will get redacted too\nsys_stream.setFormatter(jsonlogger.JsonFormatter('%(name)s %(message)s'))\nroot_logger.addHandler(sys_stream)\n\nlogger = logging.getLogger(__name__)\n\nlogger.error(\"Request Failed\", extra={'url': 'https://example.com?api_key=my-secret-key'})\n# Output: {\"name\": \"__main__\", \"message\": \"Request Failed\", \"url\": \"https://example.com?api_key=****\"}\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "logredactor", "package_url": "https://pypi.org/project/logredactor/", "platform": "", "project_url": "https://pypi.org/project/logredactor/", "project_urls": null, "release_url": "https://pypi.org/project/logredactor/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Redact logs based on regex filters", "version": "0.0.1" }, "last_serial": 5679908, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "faa541b0d46dc9e39812796f62a601aa", "sha256": "1df30bdfeb35d462a74ce96e90e63f6a832bdea1b03d14651e838b6927d8be64" }, "downloads": -1, "filename": "logredactor-0.0.1.tar.gz", "has_sig": false, "md5_digest": "faa541b0d46dc9e39812796f62a601aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2328, "upload_time": "2019-08-15T00:05:03", "url": "https://files.pythonhosted.org/packages/e3/f1/40d490e4aec9adb3a03664221020ce275b9c9a21fb552eefa4a0b322aa73/logredactor-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "faa541b0d46dc9e39812796f62a601aa", "sha256": "1df30bdfeb35d462a74ce96e90e63f6a832bdea1b03d14651e838b6927d8be64" }, "downloads": -1, "filename": "logredactor-0.0.1.tar.gz", "has_sig": false, "md5_digest": "faa541b0d46dc9e39812796f62a601aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2328, "upload_time": "2019-08-15T00:05:03", "url": "https://files.pythonhosted.org/packages/e3/f1/40d490e4aec9adb3a03664221020ce275b9c9a21fb552eefa4a0b322aa73/logredactor-0.0.1.tar.gz" } ] }