PlexKodiConnect/resources/lib/loghandler.py

28 lines
792 B
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import xbmc
2017-09-06 13:31:15 +02:00
###############################################################################
LEVELS = {
logging.ERROR: xbmc.LOGERROR,
logging.WARNING: xbmc.LOGWARNING,
2020-12-18 19:32:28 +01:00
logging.INFO: xbmc.LOGINFO,
2017-09-06 13:31:15 +02:00
logging.DEBUG: xbmc.LOGDEBUG
}
###############################################################################
def config():
2016-08-29 19:31:41 +02:00
logger = logging.getLogger('PLEX')
logger.addHandler(LogHandler())
logger.setLevel(logging.DEBUG)
class LogHandler(logging.StreamHandler):
def __init__(self):
logging.StreamHandler.__init__(self)
2020-12-18 19:32:28 +01:00
self.setFormatter(logging.Formatter(fmt='%(name)s: %(message)s'))
def emit(self, record):
2020-12-19 07:30:40 +01:00
xbmc.log(self.format(record), level=LEVELS[record.levelno])