From c559f2fff6e17419c977e637f53267740e9b99ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Wed, 10 Jul 2019 00:18:40 +0200 Subject: [PATCH] Strip pluginpath from logged stacktraces --- resources/lib/helper/loghandler.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/resources/lib/helper/loghandler.py b/resources/lib/helper/loghandler.py index 49b71940..5890bb7a 100644 --- a/resources/lib/helper/loghandler.py +++ b/resources/lib/helper/loghandler.py @@ -7,6 +7,7 @@ from __future__ import print_function import os import logging +import traceback import xbmc import xbmcaddon @@ -119,6 +120,22 @@ class MyFormatter(logging.Formatter): return result + def formatException(self, exc_info): + _pluginpath_real = os.path.realpath(__pluginpath__) + res = [] + + for o in traceback.format_exception(*exc_info): + if o.startswith(' File "'): + # If this split can't handle your file names, you should seriously consider renaming your files. + fn = o.split(' File "', 2)[1].split('", line ', 1)[0] + rfn = os.path.realpath(fn) + if rfn.startswith(_pluginpath_real): + o = o.replace(fn, os.path.relpath(rfn, _pluginpath_real)) + + res.append(o) + + return ''.join(res) + def _gen_rel_path(self, record): if record.pathname: record.relpath = os.path.relpath(record.pathname, __pluginpath__)