Add file and line number to log output.

This commit is contained in:
Odd Stråbø 2019-07-08 01:24:05 +02:00
parent 5df3077a74
commit 0549a8b0ea
1 changed files with 21 additions and 4 deletions

View File

@ -1,16 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
##################################################################################################
import os
import logging
import xbmc
import xbmcaddon
import database
from . import window, settings
##################################################################################################
__addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin')
__pluginpath__ = xbmc.translatePath(__addon__.getAddonInfo('path').decode('utf-8'))
##################################################################################################
def config():
@ -18,6 +28,7 @@ def config():
logger.addHandler(LogHandler())
logger.setLevel(logging.DEBUG)
def reset():
for handler in logging.getLogger('JELLYFIN').handlers:
@ -95,9 +106,11 @@ class MyFormatter(logging.Formatter):
# when the logger formatter was instantiated
format_orig = self._fmt
self._gen_rel_path(record)
# Replace the original format with one customized by logging level
if record.levelno in (logging.DEBUG, logging.ERROR):
self._fmt = '%(name)s -> %(levelname)s:: %(message)s'
#if record.levelno not in [logging.INFO]:
self._fmt = '%(name)s -> %(levelname)s::%(relpath)s:%(lineno)s %(message)s'
# Call the original formatter class to do the grunt work
result = logging.Formatter.format(self, record)
@ -106,3 +119,7 @@ class MyFormatter(logging.Formatter):
self._fmt = format_orig
return result
def _gen_rel_path(self, record):
if record.pathname:
record.relpath = os.path.relpath(record.pathname, __pluginpath__)