Skip to main content

Log Sanitizer

Project description

python_log_sanitizer

CircleCI PyPI version Maintainability Test Coverage

Python log sanitizer

Instalation

Pipenv

    pipenv install python_log_sanitizer 

Pip

    pip install python_log_sanitizer 

Usage

To run this example please install python-json-logger:

pip install python-json-logger
LOG_CONFIG = {
    "version": 1,
    "formatters": {
        "json": {
            "class": "pythonjsonlogger.jsonlogger.JsonFormatter",
            "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s"
        }
    },
    "filters": {
        "sanitizer": {
            "()" : "python_log_sanitizer.SanitizerFilter",
            "patterns": ["extra"],
            "placeholder": "*"
        }
    },
    "handlers": {
        "json": {
            "class": "logging.StreamHandler",
            "formatter": "json"
        }
    },
    "loggers": {
        "root": {
            "level": "INFO",
            "handlers": ["json"],
            "filters": ["sanitizer"]
        }
    }
}
import logging

from logging import config

config.dictConfig(LOG_CONFIG) # load log config from dict

logger = logging.getLogger("root") # get root logger instance


logger.info("farofa", extra={"extra": "farofa"}) # log message with extra arguments  

Example output:

{"asctime": "2018-11-04 23:01:55,804", "levelname": "INFO", "module": "<ipython-input-8-f8c68848bfbe>", "message": "farofa", "extra": "*"}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-log-sanitizer, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size python_log_sanitizer-0.0.3-py3-none-any.whl (4.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size python_log_sanitizer-0.0.3.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page