By default the Twilio Python client seems to log out personal information (emails and numbers). I know you can access the logger like this twilio_logger = logging.getLogger('twilio.http_client')
Is there a simple setting change we can make to filter out this personal information, either directly through the library or by changing the logger?
NOTE: I have attempted to do this by creating a custom formatter:
class SensitiveDataFormatter(logging.Formatter):
"""Formatter that removes sensitive information in urls."""
@staticmethod
def _filter(s):
print('filter')
return re.sub(r'([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})', r'[email_redacted]', s)
def format(self, record):
original = logging.Formatter.format(self, record)
return self._filter(original)
LOGGING = {
'version': 1,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'sensitive'
},
},
'root': {
'handlers': ['console'],
'level': 'INFO'
},
'formatters': {
'sensitive': {
'()': 'my_project.settings.logging.sensitive_data_formatter.SensitiveDataFormatter'
}
}
}
This works in the general case, however I'm struggling to apply it to Twilio
It seems that you can apply filters to Python loggers using logger config and a custom class that inherits from
logging.Filter
.I'm not a Python developer, so pointing you to this blog post is the best way I can answer this question. I will note that the post appears to be from 2014, so may need updates for Python 3, but the Python logging documentation is also pretty extensive, so should help you out here.