Overwriting logging.Formatter._fmt seems to

no longer work in Python 3
This commit is contained in:
Odd Stråbø 2020-04-19 04:37:58 +02:00
parent 795dfd38df
commit 6c5ac6292d

View file

@ -61,10 +61,7 @@ class LogHandler(logging.StreamHandler):
for token in self.sensitive['Token']: for token in self.sensitive['Token']:
string = string.replace(token or "{token}", "{jellyfin-token}") string = string.replace(token or "{token}", "{jellyfin-token}")
try: xbmc.log(string, level=xbmc.LOGNOTICE)
xbmc.log(string, level=xbmc.LOGNOTICE)
except UnicodeEncodeError:
xbmc.log(string, level=xbmc.LOGNOTICE)
@classmethod @classmethod
def _get_log_level(cls, level): def _get_log_level(cls, level):
@ -85,27 +82,15 @@ class LogHandler(logging.StreamHandler):
class MyFormatter(logging.Formatter): class MyFormatter(logging.Formatter):
def __init__(self, fmt="%(name)s -> %(message)s"): def __init__(self, fmt='%(name)s -> %(levelname)s::%(relpath)s:%(lineno)s %(message)s'):
logging.Formatter.__init__(self, fmt) logging.Formatter.__init__(self, fmt)
def format(self, record): def format(self, record):
# Save the original format configured by the user
# when the logger formatter was instantiated
format_orig = self._fmt
self._gen_rel_path(record) self._gen_rel_path(record)
# Replace the original format with one customized by logging level
self._fmt = '%(name)s -> %(levelname)s::%(relpath)s:%(lineno)s %(message)s'
# Call the original formatter class to do the grunt work # Call the original formatter class to do the grunt work
result = logging.Formatter.format(self, record) result = logging.Formatter.format(self, record)
# Restore the original format configured by the user
self._fmt = format_orig
return result return result
def formatException(self, exc_info): def formatException(self, exc_info):