Commits

Marius Gedminas  committed 45fbe91

If keep_tracebacks = yes, show me the code that produced each log message.

  • Participants
  • Parent commits b12c4e6

Comments (0)

Files changed (2)

File dozer/logview.py

 import re
 import time
 import itertools
+import traceback
+import sys
 
 from mako.lookup import TemplateLookup
 from paste import urlparser
+from paste.util.converters import asbool
 from webob import Request, Response
 from webob import exc
 
         self.logger = logging.getLogger(__name__)
         self.loglevel = getattr(logging, loglevel)
 
+        self.keep_tracebacks = asbool(kwargs.get('keep_tracebacks',
+                                                 config.get('keep_tracebacks',
+                                                            False)))
+
         reqhandler = RequestHandler()
         reqhandler.setLevel(self.loglevel)
+        reqhandler.keep_tracebacks = self.keep_tracebacks
         logging.getLogger('').addHandler(reqhandler)
         self.reqhandler = reqhandler
 
         """Initialize the handler."""
         logging.Handler.__init__(self)
         self.buffer = {}
+        self.keep_tracebacks = False
 
     def emit(self, record):
         """Emit a record.
         the buffer.
         """ 
         self.buffer.setdefault(record.thread, []).append(record)
+        if self.keep_tracebacks:
+            record.traceback = ''.join(traceback.format_stack(sys._getframe(6)))
 
     def pop_events(self, thread_id):
         """Return all the events logged for particular thread"""

File dozer/templates/logbar.mako

                     % else:
                         ${msg | h}\
                     % endif
+                    % if hasattr(event, 'traceback'):
+                    <span style="float: right; cursor: pointer; text-decoration: underline;" onclick="javascript:DLV.show_block('${'tb%s' % id(event)}')">TB</span>
+                    <pre id="${'tb%s' % id(event)}" style="display: none; padding-top: 1em">
+${event.traceback}
+</pre>
+                    % endif
                 </td>
             </tr>
         <% prev_event = event %>
     }
     return false;
 };
+DLV.show_block = function(name) {
+    var elem = DLV.getEBI(name);
+    if (elem.style.display == 'block') {
+        elem.style.display = 'none';
+    } else {
+        elem.style.display = 'block';
+    }
+    return false;
+};
 </script>