mirror of
https://github.com/moparisthebest/SickRage
synced 2025-01-05 19:08:02 -05:00
Added sensitive data filter to logger.
This commit is contained in:
parent
5a3d11a0fe
commit
e9affae8f8
@ -51,6 +51,12 @@ class NullFilter(logging.Filter):
|
|||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
pass
|
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):
|
class CensorLoggingAdapter(logging.LoggerAdapter):
|
||||||
def process(self, msg, kwargs):
|
def process(self, msg, kwargs):
|
||||||
@ -101,6 +107,7 @@ class Logger(object):
|
|||||||
if self.consoleLogging:
|
if self.consoleLogging:
|
||||||
console = logging.StreamHandler()
|
console = logging.StreamHandler()
|
||||||
console.setFormatter(logging.Formatter('%(asctime)s %(levelname)s::%(message)s', '%H:%M:%S'))
|
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)
|
console.setLevel(INFO if not self.debugLogging else DEBUG)
|
||||||
|
|
||||||
for logger in self.loggers:
|
for logger in self.loggers:
|
||||||
@ -110,6 +117,7 @@ class Logger(object):
|
|||||||
if self.fileLogging:
|
if self.fileLogging:
|
||||||
rfh = logging.handlers.RotatingFileHandler(self.logFile, maxBytes=1024 * 1024, backupCount=5, encoding='utf-8')
|
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.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%Y-%m-%d %H:%M:%S'))
|
||||||
|
rfh.addFilter(CensorFilter())
|
||||||
rfh.setLevel(DEBUG)
|
rfh.setLevel(DEBUG)
|
||||||
|
|
||||||
for logger in self.loggers:
|
for logger in self.loggers:
|
||||||
|
Loading…
Reference in New Issue
Block a user