原木消毒剂
python-log-sanitizer的Python项目详细描述
python_log_消毒剂
python日志消毒剂
安装
pipenv
pipenv install python_log_sanitizer
PIP
pip install python_log_sanitizer
用法
要运行此示例,请安装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"]}}}importloggingfromloggingimportconfigconfig.dictConfig(LOG_CONFIG)# load log config from dictlogger=logging.getLogger("root")# get root logger instancelogger.info("farofa",extra={"extra":"farofa"})# log message with extra arguments
示例输出:
{"asctime":"2018-11-04 23:01:55,804","levelname":"INFO","module":"<ipython-input-8-f8c68848bfbe>","message":"farofa","extra":"*"}