diff options
author | ianb <devnull@localhost> | 2006-05-09 23:06:39 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2006-05-09 23:06:39 +0000 |
commit | 82b170ea9a75b0f4370d4f07a2c6b03da7d39bff (patch) | |
tree | 69041f29771ad6c8b9946f22a6aed2cad8d7f35c /paste/evalexception | |
parent | a3c4265be10850dc9a788f9a90612f49e12b0cd9 (diff) | |
download | paste-82b170ea9a75b0f4370d4f07a2c6b03da7d39bff.tar.gz |
Added /_debug/summary, where you get JSON-format summary of all stored-in-memory exception reports
Diffstat (limited to 'paste/evalexception')
-rw-r--r-- | paste/evalexception/middleware.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/paste/evalexception/middleware.py b/paste/evalexception/middleware.py index 31e569c..2b36c12 100644 --- a/paste/evalexception/middleware.py +++ b/paste/evalexception/middleware.py @@ -186,18 +186,40 @@ class EvalException(object): return method(environ, start_response) def media(self, environ, start_response): + """ + Static path where images and other files live + """ app = urlparser.StaticURLParser( os.path.join(os.path.dirname(__file__), 'media')) return app(environ, start_response) media.exposed = True def mochikit(self, environ, start_response): + """ + Static path where MochiKit lives + """ app = urlparser.StaticURLParser( os.path.join(os.path.dirname(__file__), 'mochikit')) return app(environ, start_response) mochikit.exposed = True + def summary(self, environ, start_response): + """ + Returns a JSON-format summary of all the cached + exception reports + """ + start_response('200 OK', [('Content-type', 'text/x-json')]) + data = []; + items = self.debug_infos.values() + items.sort(lambda a, b: cmp(a.created, b.created)) + data = [item.json() for item in items] + return [repr(data)] + summary.exposed = True + def view(self, environ, start_response): + """ + View old exception reports + """ id = int(request.path_info_pop(environ)) if id not in self.debug_infos: start_response( @@ -287,7 +309,7 @@ class EvalException(object): exc_data = collector.collect_exception(*exc_info) debug_info = DebugInfo(count, exc_info, exc_data, base_path, - environ) + environ, view_uri) assert count not in self.debug_infos self.debug_infos[count] = debug_info @@ -342,11 +364,13 @@ class EvalException(object): class DebugInfo(object): def __init__(self, counter, exc_info, exc_data, base_path, - environ): + environ, view_uri): self.counter = counter self.exc_data = exc_data self.base_path = base_path self.environ = environ + self.view_uri = view_uri + self.created = time.time() self.exc_type, self.exc_value, self.tb = exc_info __exception_formatter__ = 1 self.frames = [] @@ -360,6 +384,16 @@ class DebugInfo(object): tb = tb.tb_next n += 1 + def json(self): + """Return the JSON-able representation of this object""" + return { + 'uri': self.view_uri, + 'created': time.strftime('%c', time.gmtime(self.created)), + 'created_timestamp': self.created, + 'exception_type': str(self.exc_type), + 'exception': str(self.exc_value), + } + def frame(self, tbid): for frame in self.frames: if id(frame) == tbid: |