Improve leap_assert traceback logging
authorTomás Touceda <chiiph@leap.se>
Fri, 5 Jul 2013 17:06:02 +0000 (14:06 -0300)
committerTomás Touceda <chiiph@leap.se>
Fri, 5 Jul 2013 17:09:09 +0000 (14:09 -0300)
changes/bug2895_improve_leap_assert [new file with mode: 0644]
src/leap/common/check.py

diff --git a/changes/bug2895_improve_leap_assert b/changes/bug2895_improve_leap_assert
new file mode 100644 (file)
index 0000000..8caea7e
--- /dev/null
@@ -0,0 +1,2 @@
+  o Improve leap_assert so that it only prints the traceback from the
+    leap_assert call up. Closes #2895
\ No newline at end of file
index a2d39a6..e6b0b52 100644 (file)
@@ -18,7 +18,6 @@
 Set of functions to help checking situations
 """
 
-import inspect
 import logging
 import traceback
 
@@ -39,9 +38,11 @@ def leap_assert(condition, message=""):
     if not condition:
         logger.error("Bug: %s" % (message,))
         try:
-            frame = inspect.currentframe()
-            stack_trace = traceback.format_stack(frame)
-            logger.error(''.join(stack_trace))
+            for formatted_line in traceback.format_list(
+                    traceback.extract_stack()[:-1]):
+                for line in formatted_line.split("\n"):
+                    if len(line.strip()) > 0:
+                        logger.error(line)
         except Exception as e:
             logger.error("Bug in leap_assert: %r" % (e,))
     assert condition, message