fix bug where only exception is passed to logger

This commit is contained in:
Kenneth Kehl
2024-06-12 10:17:23 -07:00
parent d1ab771756
commit 2a005076d0

View File

@@ -123,7 +123,12 @@ class PIIFilter(logging.Filter):
# and email addresses, masking them. Ultimately this will probably get
# refactored into a 'SafeLogger' subclass or something, but let's start here
# with phones.
# Sometimes just an exception object is passed in for the message, skip those.
if not isinstance(msg, str):
return msg
phones = re.findall("(?:\\+ *)?\\d[\\d\\- ]{7,}\\d", msg)
phones = [phone.replace("-", "").replace(" ", "") for phone in phones]
for phone in phones:
msg = msg.replace(phone, f"1XXXXX{phone[-5:]}")