Fix encoding for PKC logging

This commit is contained in:
croneter 2020-12-19 07:30:40 +01:00
parent 1d46779d57
commit 599f134204

View file

@ -12,22 +12,6 @@ LEVELS = {
############################################################################### ###############################################################################
def try_encode(uniString, encoding='utf-8'):
"""
Will try to encode uniString (in unicode) to encoding. This possibly
fails with e.g. Android TV's Python, which does not accept arguments for
string.encode()
"""
if isinstance(uniString, str):
# already encoded
return uniString
try:
uniString = uniString.encode(encoding, "ignore")
except TypeError:
uniString = uniString.encode()
return uniString
def config(): def config():
logger = logging.getLogger('PLEX') logger = logging.getLogger('PLEX')
logger.addHandler(LogHandler()) logger.addHandler(LogHandler())
@ -40,10 +24,4 @@ class LogHandler(logging.StreamHandler):
self.setFormatter(logging.Formatter(fmt='%(name)s: %(message)s')) self.setFormatter(logging.Formatter(fmt='%(name)s: %(message)s'))
def emit(self, record): def emit(self, record):
if isinstance(record.msg, str): xbmc.log(self.format(record), level=LEVELS[record.levelno])
record.msg = record.msg.encode('utf-8')
try:
xbmc.log(self.format(record), level=LEVELS[record.levelno])
except UnicodeEncodeError:
xbmc.log(try_encode(self.format(record)),
level=LEVELS[record.levelno])