From 8cec8ecfd5bcd21a3433abeb8db776c1d12b953b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Mon, 26 Oct 2020 17:25:37 +0100 Subject: [PATCH] Fix logging for Kodi Matrix (#48) --- resources/lib/kodilogging.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/resources/lib/kodilogging.py b/resources/lib/kodilogging.py index 9f797fd..f4c470d 100644 --- a/resources/lib/kodilogging.py +++ b/resources/lib/kodilogging.py @@ -8,6 +8,8 @@ import logging import xbmc import xbmcaddon +from resources.lib import kodiutils + ADDON = xbmcaddon.Addon() @@ -18,6 +20,11 @@ class KodiLogHandler(logging.StreamHandler): logging.StreamHandler.__init__(self) formatter = logging.Formatter("[{}] [%(name)s] %(message)s".format(ADDON.getAddonInfo("id"))) self.setFormatter(formatter) + # xbmc.LOGNOTICE is deprecated in Kodi 19 Matrix + if kodiutils.kodi_version_major() > 18: + self.info_level = xbmc.LOGINFO + else: + self.info_level = xbmc.LOGNOTICE def emit(self, record): """ Emit a log message """ @@ -25,15 +32,15 @@ class KodiLogHandler(logging.StreamHandler): logging.CRITICAL: xbmc.LOGFATAL, logging.ERROR: xbmc.LOGERROR, logging.WARNING: xbmc.LOGWARNING, - logging.INFO: xbmc.LOGNOTICE, + logging.INFO: self.info_level, logging.DEBUG: xbmc.LOGDEBUG, logging.NOTSET: xbmc.LOGNONE, } - # Map DEBUG level to LOGNOTICE if debug logging setting has been activated + # Map DEBUG level to info_level if debug logging setting has been activated # This is for troubleshooting only if ADDON.getSetting('debug_logging') == 'true': - levels[logging.DEBUG] = xbmc.LOGNOTICE + levels[logging.DEBUG] = self.info_level try: xbmc.log(self.format(record), levels[record.levelno]) @@ -49,4 +56,3 @@ def config(): logger = logging.getLogger() logger.setLevel(logging.DEBUG) # Make sure we pass all messages, Kodi will do some filtering itself. logger.addHandler(KodiLogHandler()) - logger.setLevel(logging.DEBUG)