diff --git a/resources/lib/loghandler.py b/resources/lib/loghandler.py index 9aebb3e9..f81c962d 100644 --- a/resources/lib/loghandler.py +++ b/resources/lib/loghandler.py @@ -2,8 +2,6 @@ ############################################################################### import logging import xbmc - -from utils import tryEncode ############################################################################### LEVELS = { logging.ERROR: xbmc.LOGERROR, @@ -14,6 +12,22 @@ LEVELS = { ############################################################################### +def tryEncode(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(): logger = logging.getLogger('PLEX') logger.addHandler(LogHandler())