summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar GammaC0de <GammaC0de@users.noreply.github.com> 2015-10-13 02:15:44 +0200
committerGravatar GammaC0de <GammaC0de@users.noreply.github.com> 2015-10-13 02:15:44 +0200
commit5759110d899d31c9f788c15a38cc83cd54268c26 (patch)
tree6a0a9c13d1a030c068f6a174773aaefb3e8f4bf0 /module
parent[XFSAccount] Error handling support (diff)
downloadpyload-5759110d899d31c9f788c15a38cc83cd54268c26.tar.xz
[Plugin] improve error tracing (2)
Diffstat (limited to 'module')
-rw-r--r--module/plugins/internal/Plugin.py63
1 files changed, 39 insertions, 24 deletions
diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py
index 3ad878c1b..75a2903cd 100644
--- a/module/plugins/internal/Plugin.py
+++ b/module/plugins/internal/Plugin.py
@@ -171,6 +171,29 @@ def which(program):
return exe_file
+#@TODO: Move to utils in 0.4.10
+def format_exc(frame=None):
+ """
+ Format call-stack and display exception information (if availible)
+ """
+ exception_info = sys.exc_info()
+ callstack_list = traceback.extract_stack(frame)
+ callstack_list = callstack_list[:-1]
+
+ exception_desc = ""
+ if exception_info[0] is not None:
+ exception_callstack_list = traceback.extract_tb(exception_info[2])
+ if callstack_list[-1][0] == exception_callstack_list[0][0]: #Does this exception belongs to us?
+ callstack_list = callstack_list[:-1]
+ callstack_list.extend(exception_callstack_list)
+ exception_desc = "".join(traceback.format_exception_only(exception_info[0], exception_info[1]))
+
+ traceback_str = "Traceback (most recent call last):\n"
+ traceback_str += "".join(traceback.format_list(callstack_list))
+ traceback_str += exception_desc
+ traceback_str = traceback_str[:-1] #Removing the last '\n'
+ return traceback_str
+
def seconds_to_nexthour(strict=False):
now = datetime.datetime.today()
nexthour = now.replace(minute=0 if strict else 1, second=0, microsecond=0) + datetime.timedelta(hours=1)
@@ -312,47 +335,39 @@ class Plugin(object):
def log_debug(self, *args, **kwargs):
self._log("debug", self.__type__, self.__name__, args)
- if self.pyload.debug and kwargs.get('trace'):
- frame = inspect.currentframe()
- print "Traceback (most recent call last):"
- traceback.print_stack(frame.f_back)
- del frame
+ if self.pyload.debug and kwargs.get('trace', False):
+ self.log_exc("debug")
def log_info(self, *args, **kwargs):
self._log("info", self.__type__, self.__name__, args)
- if self.pyload.debug and kwargs.get('trace'):
- frame = inspect.currentframe()
- print "Traceback (most recent call last):"
- traceback.print_stack(frame.f_back)
- del frame
+ if kwargs.get('trace', False):
+ self.log_exc("info")
def log_warning(self, *args, **kwargs):
self._log("warning", self.__type__, self.__name__, args)
- if self.pyload.debug and kwargs.get('trace'):
- frame = inspect.currentframe()
- print "Traceback (most recent call last):"
- traceback.print_stack(frame.f_back)
- del frame
+ if kwargs.get('trace', False):
+ self.log_exc("warning")
def log_error(self, *args, **kwargs):
self._log("error", self.__type__, self.__name__, args)
- if self.pyload.debug and kwargs.get('trace', True):
- frame = inspect.currentframe()
- print "Traceback (most recent call last):"
- traceback.print_stack(frame.f_back)
- del frame
+ if kwargs.get('trace', False):
+ self.log_exc("error")
def log_critical(self, *args, **kwargs):
self._log("critical", self.__type__, self.__name__, args)
if kwargs.get('trace', True):
- frame = inspect.currentframe()
- print "Traceback (most recent call last):"
- traceback.print_stack(frame.f_back)
- del frame
+ self.log_exc("critical")
+
+
+ def log_exc(self, level):
+ frame = inspect.currentframe()
+ log = getattr(self.pyload.log, level)
+ log(format_exc(frame.f_back))
+ del frame
def set_permissions(self, path):