diff --git a/resources/lib/loghandler.py b/resources/lib/loghandler.py index a89724c..abb124c 100644 --- a/resources/lib/loghandler.py +++ b/resources/lib/loghandler.py @@ -12,8 +12,13 @@ from kodi_six import xbmc, xbmcaddon from .utils import translate_path -__addon__ = xbmcaddon.Addon(id='plugin.video.jellycon') -__pluginpath__ = translate_path(__addon__.getAddonInfo('path')) +try: + __addon__ = xbmcaddon.Addon(id='plugin.video.jellycon') + __pluginpath__ = translate_path(__addon__.getAddonInfo('path')) +except Exception: + # During installation/update, addon might not be fully registered yet + __addon__ = None + __pluginpath__ = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) def getLogger(name=None): @@ -32,9 +37,14 @@ class LogHandler(logging.StreamHandler): self.sensitive = {'Token': [], 'Server': []} - settings = xbmcaddon.Addon() - self.server = settings.getSetting('server_address') - self.debug = settings.getSetting('log_debug') + try: + settings = xbmcaddon.Addon() + self.server = settings.getSetting('server_address') + self.debug = settings.getSetting('log_debug') + except Exception: + # During installation/update, settings might not be available yet + self.server = '' + self.debug = 'false' def emit(self, record): @@ -96,13 +106,16 @@ class MyFormatter(logging.Formatter): return result def formatException(self, exc_info): - _pluginpath_real = os.path.realpath(__pluginpath__) + try: + _pluginpath_real = os.path.realpath(__pluginpath__) + except Exception: + _pluginpath_real = None res = [] for o in traceback.format_exception(*exc_info): o = ensure_text(o, get_filesystem_encoding()) - if o.startswith(' File "'): + if _pluginpath_real and o.startswith(' File "'): """ If this split can't handle your file names, you should seriously consider renaming your files. @@ -118,7 +131,10 @@ class MyFormatter(logging.Formatter): def _gen_rel_path(self, record): if record.pathname: - record.relpath = os.path.relpath(record.pathname, __pluginpath__) + try: + record.relpath = os.path.relpath(record.pathname, __pluginpath__) + except Exception: + record.relpath = record.pathname def get_filesystem_encoding():