2016-07-24 18:59:48 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-09-06 21:31:15 +10:00
|
|
|
###############################################################################
|
2016-07-24 18:59:48 +10:00
|
|
|
import logging
|
|
|
|
import xbmc
|
|
|
|
|
2017-09-06 21:31:15 +10:00
|
|
|
from utils import tryEncode
|
|
|
|
###############################################################################
|
|
|
|
LEVELS = {
|
|
|
|
logging.ERROR: xbmc.LOGERROR,
|
|
|
|
logging.WARNING: xbmc.LOGWARNING,
|
|
|
|
logging.INFO: xbmc.LOGNOTICE,
|
|
|
|
logging.DEBUG: xbmc.LOGDEBUG
|
|
|
|
}
|
|
|
|
###############################################################################
|
2016-07-24 18:59:48 +10:00
|
|
|
|
|
|
|
|
|
|
|
def config():
|
2016-08-30 03:31:41 +10:00
|
|
|
logger = logging.getLogger('PLEX')
|
2016-07-24 18:59:48 +10:00
|
|
|
logger.addHandler(LogHandler())
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
|
|
|
|
class LogHandler(logging.StreamHandler):
|
|
|
|
def __init__(self):
|
|
|
|
logging.StreamHandler.__init__(self)
|
2017-09-06 21:31:15 +10:00
|
|
|
self.setFormatter(logging.Formatter(fmt="%(name)s: %(message)s"))
|
2016-07-24 18:59:48 +10:00
|
|
|
|
|
|
|
def emit(self, record):
|
|
|
|
try:
|
2017-09-06 21:31:15 +10:00
|
|
|
xbmc.log(self.format(record), level=LEVELS[record.levelno])
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
xbmc.log(tryEncode(self.format(record)),
|
|
|
|
level=LEVELS[record.levelno])
|