mirror of
https://github.com/morpheus65535/bazarr
synced 2025-02-23 22:41:34 +00:00
Initial commit
This commit is contained in:
parent
b2141f4bd0
commit
c21c2869f7
3 changed files with 107 additions and 43 deletions
97
bazarr/logger.py
Normal file
97
bazarr/logger.py
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
|
from get_argv import config_dir
|
||||||
|
from get_settings import get_general_settings
|
||||||
|
|
||||||
|
log_level = get_general_settings()[4]
|
||||||
|
if log_level is None:
|
||||||
|
log_level = "INFO"
|
||||||
|
|
||||||
|
|
||||||
|
class OneLineExceptionFormatter(logging.Formatter):
|
||||||
|
def formatException(self, exc_info):
|
||||||
|
"""
|
||||||
|
Format an exception so that it prints on a single line.
|
||||||
|
"""
|
||||||
|
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:
|
||||||
|
s = s.replace('\n', '') + '|'
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
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 ''
|
||||||
|
|
||||||
|
|
||||||
|
def configure_logging():
|
||||||
|
log = logging.getLogger()
|
||||||
|
log.handlers = []
|
||||||
|
|
||||||
|
global fh
|
||||||
|
fh = TimedRotatingFileHandler(os.path.join(config_dir, 'log/bazarr.log'), when="midnight", interval=1,
|
||||||
|
backupCount=7)
|
||||||
|
f = OneLineExceptionFormatter('%(asctime)s|%(levelname)-8s|%(name)-32s|%(message)s|',
|
||||||
|
'%d/%m/%Y %H:%M:%S')
|
||||||
|
fh.setFormatter(f)
|
||||||
|
fh.addFilter(BlacklistFilter())
|
||||||
|
logging.getLogger("enzyme").setLevel(logging.CRITICAL)
|
||||||
|
logging.getLogger("apscheduler").setLevel(logging.WARNING)
|
||||||
|
if log_level == 'debug':
|
||||||
|
logging.getLogger("subliminal").setLevel(logging.DEBUG)
|
||||||
|
else:
|
||||||
|
logging.getLogger("subliminal").setLevel(logging.CRITICAL)
|
||||||
|
logging.getLogger("guessit").setLevel(logging.WARNING)
|
||||||
|
logging.getLogger("rebulk").setLevel(logging.WARNING)
|
||||||
|
logging.getLogger("stevedore.extension").setLevel(logging.CRITICAL)
|
||||||
|
log.setLevel(log_level)
|
||||||
|
log.addHandler(fh)
|
||||||
|
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
cf = NoExceptionFormatter('%(asctime)s - %(levelname)s :: %(message)s',
|
||||||
|
'%Y-%m-%d %H:%M:%S')
|
||||||
|
ch.setFormatter(cf)
|
||||||
|
ch.setLevel(logging.INFO)
|
||||||
|
log.addHandler(ch)
|
||||||
|
|
||||||
|
|
||||||
|
class BlacklistFilter(logging.Filter):
|
||||||
|
"""
|
||||||
|
Log filter for blacklisted tokens and passwords
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def filter(self, record):
|
||||||
|
try:
|
||||||
|
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 []
|
||||||
|
for apikey in apikeys:
|
||||||
|
arg = arg.replace(apikey, 8 * '*' + apikey[-2:])
|
||||||
|
args.append(arg)
|
||||||
|
record.args = tuple(args)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def empty_log():
|
||||||
|
fh.doRollover()
|
||||||
|
|
|
@ -21,42 +21,7 @@ from update_db import *
|
||||||
|
|
||||||
from get_settings import get_general_settings, get_proxy_settings
|
from get_settings import get_general_settings, get_proxy_settings
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
from logger import configure_logging, empty_log
|
||||||
|
|
||||||
log_level = get_general_settings()[4]
|
|
||||||
if log_level is None:
|
|
||||||
log_level = "INFO"
|
|
||||||
|
|
||||||
class OneLineExceptionFormatter(logging.Formatter):
|
|
||||||
def formatException(self, exc_info):
|
|
||||||
"""
|
|
||||||
Format an exception so that it prints on a single line.
|
|
||||||
"""
|
|
||||||
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:
|
|
||||||
s = s.replace('\n', '') + '|'
|
|
||||||
return s
|
|
||||||
|
|
||||||
def configure_logging():
|
|
||||||
global fh
|
|
||||||
fh = TimedRotatingFileHandler(os.path.join(config_dir, 'log/bazarr.log'), when="midnight", interval=1, backupCount=7)
|
|
||||||
f = OneLineExceptionFormatter('%(asctime)s|%(levelname)s|%(message)s|',
|
|
||||||
'%d/%m/%Y %H:%M:%S')
|
|
||||||
fh.setFormatter(f)
|
|
||||||
logging.getLogger("enzyme").setLevel(logging.CRITICAL)
|
|
||||||
logging.getLogger("apscheduler").setLevel(logging.WARNING)
|
|
||||||
logging.getLogger("subliminal").setLevel(logging.CRITICAL)
|
|
||||||
logging.getLogger("guessit").setLevel(logging.WARNING)
|
|
||||||
logging.getLogger("rebulk").setLevel(logging.WARNING)
|
|
||||||
logging.getLogger("stevedore.extension").setLevel(logging.CRITICAL)
|
|
||||||
root = logging.getLogger()
|
|
||||||
root.setLevel(log_level)
|
|
||||||
root.addHandler(fh)
|
|
||||||
|
|
||||||
configure_logging()
|
configure_logging()
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
@ -449,7 +414,7 @@ def emptylog():
|
||||||
authorize()
|
authorize()
|
||||||
ref = request.environ['HTTP_REFERER']
|
ref = request.environ['HTTP_REFERER']
|
||||||
|
|
||||||
fh.doRollover()
|
empty_log()
|
||||||
logging.info('BAZARR Log file emptied')
|
logging.info('BAZARR Log file emptied')
|
||||||
|
|
||||||
redirect(ref)
|
redirect(ref)
|
||||||
|
|
|
@ -34,25 +34,27 @@
|
||||||
%line = log.split('|')
|
%line = log.split('|')
|
||||||
<tr class='log' data-message="\\
|
<tr class='log' data-message="\\
|
||||||
%try:
|
%try:
|
||||||
{{line[2]}}\\
|
{{line[3]}}\\
|
||||||
%except:
|
%except:
|
||||||
\\
|
\\
|
||||||
%end
|
%end
|
||||||
" data-exception="\\
|
" data-exception="\\
|
||||||
%try:
|
%try:
|
||||||
{{line[3]}}\\
|
{{line[4]}}\\
|
||||||
%except:
|
%except:
|
||||||
\\
|
\\
|
||||||
%end
|
%end
|
||||||
">
|
">
|
||||||
<td class="collapsing"><i class="\\
|
<td class="collapsing"><i class="\\
|
||||||
%try:
|
%try:
|
||||||
%if line[1] == 'INFO':
|
%if line[1] == 'INFO ':
|
||||||
blue info circle icon \\
|
blue info circle icon \\
|
||||||
%elif line[1] == 'WARNING':
|
%elif line[1] == 'WARNING ':
|
||||||
yellow warning circle icon \\
|
yellow warning circle icon \\
|
||||||
%elif line[1] == 'ERROR':
|
%elif line[1] == 'ERROR ':
|
||||||
red bug icon \\
|
red bug icon \\
|
||||||
|
%elif line[1] == 'DEBUG ':
|
||||||
|
bug icon \\
|
||||||
%end
|
%end
|
||||||
%except:
|
%except:
|
||||||
%pass
|
%pass
|
||||||
|
@ -60,7 +62,7 @@ red bug icon \\
|
||||||
"></i></td>
|
"></i></td>
|
||||||
<td>\\
|
<td>\\
|
||||||
%try:
|
%try:
|
||||||
{{line[2]}}\\
|
{{line[3]}}\\
|
||||||
%except:
|
%except:
|
||||||
\\
|
\\
|
||||||
%end
|
%end
|
||||||
|
|
Loading…
Reference in a new issue