From 0549a8b0ea8102210e9172190d77126c5615c177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Mon, 8 Jul 2019 01:24:05 +0200 Subject: [PATCH] Add file and line number to log output. --- resources/lib/helper/loghandler.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/resources/lib/helper/loghandler.py b/resources/lib/helper/loghandler.py index 04fa723c..0ac9132e 100644 --- a/resources/lib/helper/loghandler.py +++ b/resources/lib/helper/loghandler.py @@ -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: @@ -59,7 +70,7 @@ class LogHandler(logging.StreamHandler): string = string.replace(server.encode('utf-8') or "{server}", "{jellyfin-server}") for token in self.sensitive['Token']: - string = string.replace(token.encode('utf-8') or "{token}", "{jellyfin-token}") + string = string.replace(token.encode('utf-8') or "{token}", "{jellyfin-token}") try: xbmc.log(string, level=xbmc.LOGNOTICE) @@ -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__)