Fix logging for Kodi Matrix (#48)
This commit is contained in:
parent
ed36677694
commit
8cec8ecfd5
@ -8,6 +8,8 @@ import logging
|
|||||||
import xbmc
|
import xbmc
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
|
|
||||||
|
from resources.lib import kodiutils
|
||||||
|
|
||||||
ADDON = xbmcaddon.Addon()
|
ADDON = xbmcaddon.Addon()
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +20,11 @@ class KodiLogHandler(logging.StreamHandler):
|
|||||||
logging.StreamHandler.__init__(self)
|
logging.StreamHandler.__init__(self)
|
||||||
formatter = logging.Formatter("[{}] [%(name)s] %(message)s".format(ADDON.getAddonInfo("id")))
|
formatter = logging.Formatter("[{}] [%(name)s] %(message)s".format(ADDON.getAddonInfo("id")))
|
||||||
self.setFormatter(formatter)
|
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):
|
def emit(self, record):
|
||||||
""" Emit a log message """
|
""" Emit a log message """
|
||||||
@ -25,15 +32,15 @@ class KodiLogHandler(logging.StreamHandler):
|
|||||||
logging.CRITICAL: xbmc.LOGFATAL,
|
logging.CRITICAL: xbmc.LOGFATAL,
|
||||||
logging.ERROR: xbmc.LOGERROR,
|
logging.ERROR: xbmc.LOGERROR,
|
||||||
logging.WARNING: xbmc.LOGWARNING,
|
logging.WARNING: xbmc.LOGWARNING,
|
||||||
logging.INFO: xbmc.LOGNOTICE,
|
logging.INFO: self.info_level,
|
||||||
logging.DEBUG: xbmc.LOGDEBUG,
|
logging.DEBUG: xbmc.LOGDEBUG,
|
||||||
logging.NOTSET: xbmc.LOGNONE,
|
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
|
# This is for troubleshooting only
|
||||||
if ADDON.getSetting('debug_logging') == 'true':
|
if ADDON.getSetting('debug_logging') == 'true':
|
||||||
levels[logging.DEBUG] = xbmc.LOGNOTICE
|
levels[logging.DEBUG] = self.info_level
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xbmc.log(self.format(record), levels[record.levelno])
|
xbmc.log(self.format(record), levels[record.levelno])
|
||||||
@ -49,4 +56,3 @@ def config():
|
|||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.DEBUG) # Make sure we pass all messages, Kodi will do some filtering itself.
|
logger.setLevel(logging.DEBUG) # Make sure we pass all messages, Kodi will do some filtering itself.
|
||||||
logger.addHandler(KodiLogHandler())
|
logger.addHandler(KodiLogHandler())
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user