Fix logging for Kodi Matrix (#48)

This commit is contained in:
Michaël Arnauts 2020-10-26 17:25:37 +01:00 committed by GitHub
parent ed36677694
commit 8cec8ecfd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)