Find data to redact on-the-fly corresponding to common stuff

This commit is contained in:
Alexandre Aubin 2019-06-19 23:14:48 +02:00
parent b9e4b91f1b
commit b26ec9c2fc

View file

@ -25,6 +25,7 @@
"""
import os
import re
import yaml
import collections
@ -297,10 +298,22 @@ class RedactingFormatter(Formatter):
def format(self, record):
msg = super(RedactingFormatter, self).format(record)
self.identify_data_to_redact(msg)
for data in self.data_to_redact:
msg = msg.replace(data, "**********")
return msg
def identify_data_to_redact(self, record):
# Wrapping this in a try/except because we don't want this to
# break everything in case it fails miserably for some reason :s
try:
match = re.search(r'(db_pwd|password)=(\S{3,})$', record.strip())
if match and match.group(2) not in self.data_to_redact:
self.data_to_redact.append(match.group(2))
except Exception as e:
logger.warning("Failed to parse line to try to identify data to redact ... : %s" % e)
class OperationLogger(object):