Strip pluginpath from logged stacktraces

This commit is contained in:
Odd Stråbø 2019-07-10 00:18:40 +02:00
parent 9ae99de8dd
commit c559f2fff6

View file

@ -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__)