From e9affae8f8085e30099eafe943e10f503a9c6ec4 Mon Sep 17 00:00:00 2001 From: echel0n Date: Tue, 16 Dec 2014 23:54:24 -0800 Subject: [PATCH] Added sensitive data filter to logger. --- sickbeard/logger.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sickbeard/logger.py b/sickbeard/logger.py index 411691c3..17258045 100644 --- a/sickbeard/logger.py +++ b/sickbeard/logger.py @@ -51,6 +51,12 @@ class NullFilter(logging.Filter): def filter(self, record): pass +class CensorFilter(logging.Filter): + def filter(self, record): + for k, v in censoredItems.items(): + if v and len(v) > 0 and v in record.msg: + record.msg = record.msg.replace(v, len(v) * '*') + return True class CensorLoggingAdapter(logging.LoggerAdapter): def process(self, msg, kwargs): @@ -101,6 +107,7 @@ class Logger(object): if self.consoleLogging: console = logging.StreamHandler() console.setFormatter(logging.Formatter('%(asctime)s %(levelname)s::%(message)s', '%H:%M:%S')) + console.addFilter(CensorFilter()) console.setLevel(INFO if not self.debugLogging else DEBUG) for logger in self.loggers: @@ -110,6 +117,7 @@ class Logger(object): if self.fileLogging: rfh = logging.handlers.RotatingFileHandler(self.logFile, maxBytes=1024 * 1024, backupCount=5, encoding='utf-8') rfh.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%Y-%m-%d %H:%M:%S')) + rfh.addFilter(CensorFilter()) rfh.setLevel(DEBUG) for logger in self.loggers: