Permalink
Browse files

Add post-mortem debugging.

  • Loading branch information...
1 parent 4cafec9 commit 6b400a44cd078eb6e7fb1e816f71f64287fa3983 @mcdonc mcdonc committed May 12, 2008
Showing with 105 additions and 13 deletions.
  1. +6 −0 CHANGES.txt
  2. +15 −7 README.txt
  3. +18 −0 repoze/errorlog/__init__.py
  4. +59 −0 repoze/errorlog/tests.py
  5. +7 −6 setup.py
View
@@ -1,3 +1,9 @@
+After 0.6
+
+ - Add post-mortem debug middleware (egg:repoze.errorlog#pdbpm)
+
+ - Remove versions from dependencies.
+
0.6
- Get rid of find-link point to http://dist.repoze.org in setup.py.
View
@@ -5,12 +5,9 @@ repoze.errorlog README
This package implements a WSGI Middleware filter which intercepts
exceptions and writes them to a Python 'logging' module channel
(or the 'wsgi.errors' filehandle, if no channel is configured).
-
- Installation
-
- The simple way::
-
- $ bin/easy_install --find-links=http://dist.repoze.org/ repoze.errorlog
+ It also allows the browsing of limited exception history via a
+ browser UI. It also provides middleware that allows for
+ post-mortem debugging.
Configuration
@@ -87,4 +84,15 @@ repoze.errorlog README
url = construct_url(environ, path_info=path,
querystring='entry=%s' % entry)
-
+ Post-Mortem Debugging
+
+ You will be dropped into Python's PDB post-mortem debugger if you
+ run your WSGI app in the foreground and use the
+ 'egg:repoze.errorlog#pdbpm' entry point in your Paste
+ configuration, eg.::
+
+ [pipeline:main]
+ pipeline = egg:Paste#cgitb
+ egg:repoze.errorlog#pdbpm
+ myapp
+
@@ -14,6 +14,7 @@
from logging import getLogger
import os
+import pdb
import pprint
import sys
import traceback
@@ -175,3 +176,20 @@ def make_errorlog(app, global_conf, **local_conf):
ignored_exceptions.append(ignored_exc)
ignored_exceptions = tuple(ignored_exceptions)
return ErrorLog(app, channel, keep, path, ignored_exceptions)
+
+# stolen partly from z3c.evalexception
+def PostMortemDebug(application):
+ """Middleware that catches exceptions and invokes pdb's
+ post-mortem debugging facility."""
+ def middleware(environ, start_response):
+ try:
+ return application(environ, start_response)
+ except:
+ pdb.post_mortem(sys.exc_info()[2])
+ raise
+
+ return middleware
+
+def make_post_mortem_debug(app, global_conf):
+ return PostMortemDebug(app)
+
@@ -177,6 +177,65 @@ def test_insert_error(self):
self.assertEqual(elog.errors[0].__class__, Error)
del exc_info
+class TestPDBPM(unittest.TestCase):
+ def _getFUT(self):
+ from repoze.errorlog import PostMortemDebug
+ return PostMortemDebug
+
+ def _makeOne(self, app):
+ f = self._getFUT()
+ return f(app)
+
+ def test_post_mortem_withexc(self):
+ app = DummyApplication(KeyError)
+ mw = self._makeOne(app)
+ fake_pdb = FakePDB()
+ try:
+ import repoze.errorlog
+ old_pdb = repoze.errorlog.pdb
+ repoze.errorlog.pdb = fake_pdb
+ environ = {}
+ self.assertRaises(KeyError, mw, environ, None)
+ finally:
+ repoze.errorlog.pdb = old_pdb
+ self.assertEqual(fake_pdb.called, True)
+
+ def test_post_mortem_noexc(self):
+ app = DummyApplication()
+ mw = self._makeOne(app)
+ fake_pdb = FakePDB()
+ try:
+ import repoze.errorlog
+ old_pdb = repoze.errorlog.pdb
+ repoze.errorlog.pdb = fake_pdb
+ environ = {}
+ result = mw(environ, None)
+ finally:
+ repoze.errorlog.pdb = old_pdb
+ self.assertEqual(fake_pdb.called, False)
+ self.assertEqual(result, ['hello world'])
+
+ def test_paste_constructor(self):
+ app = DummyApplication()
+ from repoze.errorlog import make_post_mortem_debug
+ mw = make_post_mortem_debug(app, None)
+ fake_pdb = FakePDB()
+ try:
+ import repoze.errorlog
+ old_pdb = repoze.errorlog.pdb
+ repoze.errorlog.pdb = fake_pdb
+ environ = {}
+ result = mw(environ, None)
+ finally:
+ repoze.errorlog.pdb = old_pdb
+ self.assertEqual(fake_pdb.called, False)
+ self.assertEqual(result, ['hello world'])
+
+class FakePDB:
+ called = False
+ def post_mortem(self, *args):
+ self.called = True
+
class DummyApplication:
def __init__(self, exc=None):
self.exc = exc
View
@@ -47,19 +47,20 @@
namespace_packages=['repoze'],
zip_safe=False,
tests_require = [
- 'meld3 >= 0.6.4',
- 'elementtree >= 1.2.6, < 1.2.7',
- 'Paste >= 1.5',
+ 'meld3',
+ 'elementtree',
+ 'Paste',
],
install_requires = [
- 'meld3 >= 0.6.4',
- 'elementtree >= 1.2.6, < 1.2.7',
- 'Paste >= 1.5',
+ 'meld3',
+ 'elementtree',
+ 'Paste',
],
test_suite="repoze.errorlog.tests",
entry_points = """\
[paste.filter_app_factory]
errorlog = repoze.errorlog:make_errorlog
+ pdbpm = repoze.errorlog:make_post_mortem_debug
"""
)

0 comments on commit 6b400a4

Please sign in to comment.