I created an overriding formatter that masks some lines as follows:
class MaskFormatter(logging.Formatter): def __init__(self, fmt, mask): logging.Formatter.__init__(self, fmt, mask) self.mask = mask def format(self, record): result = logging.Formatter.format(self, record) if result is not None and result.find(self.mask) != -1: result = result.replace(self.mask, '*' * len(self.mask)) return result
I use it as follows:
formatter = MaskFormatter('%(asctime)s %(levelname)s' + ' %(module)s %(lineno)d %(message)s', mask='abcde') hdlr.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG) hdlr.setFormatter(formatter)
however, in my journal lines, I noticed that the date-time is now also masked !! although I asked him to disguise only "abcde", can anyone help?
All log lines are prefixed with ***** instead of the actual datetime:
***** DEBUG mail
source share