diff --git a/bazarr/logger.py b/bazarr/logger.py index fb49ad4e5..d061e1899 100644 --- a/bazarr/logger.py +++ b/bazarr/logger.py @@ -15,7 +15,7 @@ class OneLineExceptionFormatter(logging.Formatter): """ result = super(OneLineExceptionFormatter, self).formatException(exc_info) return repr(result) # or format into one line however you want to - + def format(self, record): s = super(OneLineExceptionFormatter, self).format(record) if record.exc_text: @@ -27,7 +27,7 @@ class NoExceptionFormatter(logging.Formatter): def format(self, record): record.exc_text = '' # ensure formatException gets called return super(NoExceptionFormatter, self).format(record) - + def formatException(self, record): return '' @@ -37,21 +37,21 @@ def configure_logging(debug=False): log_level = "INFO" else: log_level = "DEBUG" - + logger.handlers = [] - + logger.setLevel(log_level) # Console logging ch = logging.StreamHandler() - cf = NoExceptionFormatter('%(asctime)-15s - %(name)-32s (%(thread)x) : %(levelname)s (%(module)s:%(lineno)d) ' - '- %(message)s') + cf = (debug and logging.Formatter or NoExceptionFormatter)( + '%(asctime)-15s - %(name)-32s (%(thread)x) : %(levelname)s (%(module)s:%(lineno)d) - %(message)s') ch.setFormatter(cf) ch.setLevel(log_level) # ch.addFilter(MyFilter()) logger.addHandler(ch) - + # File Logging global fh fh = TimedRotatingFileHandler(os.path.join(args.config_dir, 'log/bazarr.log'), when="midnight", interval=1, @@ -72,29 +72,30 @@ def configure_logging(debug=False): else: logging.getLogger("apscheduler").setLevel(logging.WARNING) logging.getLogger("subliminal").setLevel(logging.CRITICAL) - + logging.getLogger("enzyme").setLevel(logging.CRITICAL) logging.getLogger("guessit").setLevel(logging.WARNING) logging.getLogger("rebulk").setLevel(logging.WARNING) logging.getLogger("stevedore.extension").setLevel(logging.CRITICAL) fh.setLevel(log_level) logger.addHandler(fh) - + class MyFilter(logging.Filter): def __init__(self): pass - + def filter(self, record): if record.name != 'root': return False return True - + class BlacklistFilter(logging.Filter): """ Log filter for blacklisted tokens and passwords """ + def __init__(self): super(BlacklistFilter, self).__init__() @@ -103,7 +104,7 @@ class BlacklistFilter(logging.Filter): apikeys = re.findall(r'apikey(?:=|%3D)([a-zA-Z0-9]+)', record.msg) for apikey in apikeys: record.msg = record.msg.replace(apikey, 8 * '*' + apikey[-2:]) - + args = [] for arg in record.args: apikeys = re.findall(r'apikey(?:=|%3D)([a-zA-Z0-9]+)', arg) if isinstance(arg, basestring) else [] @@ -120,6 +121,7 @@ class PublicIPFilter(logging.Filter): """ Log filter for public IP addresses """ + def __init__(self): super(PublicIPFilter, self).__init__() @@ -132,7 +134,8 @@ class PublicIPFilter(logging.Filter): args = [] for arg in record.args: - ipv4 = re.findall(r'[0-9]+(?:\.[0-9]+){3}(?!\d*-[a-z0-9]{6})', arg) if isinstance(arg, basestring) else [] + ipv4 = re.findall(r'[0-9]+(?:\.[0-9]+){3}(?!\d*-[a-z0-9]{6})', arg) if isinstance(arg, + basestring) else [] for ip in ipv4: arg = arg.replace(ip, ip.partition('.')[0] + '.***.***.***') args.append(arg)