diff --git a/docs/source/debug-middleware-1.png b/docs/source/debug-middleware-1.png new file mode 100644 index 0000000..350e2a6 Binary files /dev/null and b/docs/source/debug-middleware-1.png differ diff --git a/docs/source/debug-middleware-2.png b/docs/source/debug-middleware-2.png new file mode 100644 index 0000000..ce83f18 Binary files /dev/null and b/docs/source/debug-middleware-2.png differ diff --git a/docs/source/development.rst b/docs/source/development.rst index f987ddf..0cc214c 100644 --- a/docs/source/development.rst +++ b/docs/source/development.rst @@ -9,7 +9,37 @@ Reloading Automatically as Files Change Debugging Pecan Applications ---------------------------- -TODO +Pecan comes with a simple debugging middleware for helping track down problems +in your applications. To enable the debugging middleware, simply set the +``debug`` flag to ``True`` in your configuration file:: + + app = { + ... + 'debug': True, + ... + } + +Once enabled, the middleware will automatically catch exceptions raised by your +application, and display the Python stack trace and WSGI environment in your +browser for easy debugging. + +.. figure:: debug-middleware-1.png + :alt: Pecan debug middleware sample output. + :width: 90% + :align: center + +To further aid in debugging, the middleware includes the ability to repeat the +offending request, automatically inserting a breakpoint, and dropping your +console into the Python debugger, ``pdb``. + +.. figure:: debug-middleware-2.png + :alt: Pecan debug middleware request debugger. + :align: center + +For more information, refer to the +`documentation for pdb `_ available on +the Python website. + Serving Static Files -------------------- diff --git a/docs/source/index.rst b/docs/source/index.rst index 64ef9f3..7b80851 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -73,6 +73,7 @@ docstrings here: pecan_decorators.rst pecan_deploy.rst pecan_hooks.rst + pecan_middleware_debug.rst pecan_jsonify.rst pecan_rest.rst pecan_routing.rst diff --git a/docs/source/pecan_middleware_debug.rst b/docs/source/pecan_middleware_debug.rst new file mode 100644 index 0000000..51dc1a2 --- /dev/null +++ b/docs/source/pecan_middleware_debug.rst @@ -0,0 +1,9 @@ +.. _pecan_middleware_debug: + +:mod:`pecan.middleware.debug` -- Pecan Debugging Middleware +=========================================================== + +.. automodule:: pecan.middleware.debug + :members: + :show-inheritance: + diff --git a/pecan/middleware/debug.py b/pecan/middleware/debug.py index f4e545f..d100e0b 100644 --- a/pecan/middleware/debug.py +++ b/pecan/middleware/debug.py @@ -231,6 +231,35 @@ class PdbMiddleware(object): class DebugMiddleware(object): + """A WSGI middleware that provides debugging assistance for development + environments. + + To enable the debugging middleware, simply set the ``debug`` flag to + ``True`` in your configuration file:: + + app = { + ... + 'debug': True, + ... + } + + Once enabled, the middleware will automatically catch exceptions raised by + your application, and display the Python stack trace and WSGI environment + in your browser for easy debugging. + + To further aid in debugging, the middleware includes the ability to repeat + the offending request, automatically inserting a breakpoint, and dropping + your console into the Python debugger, ``pdb``. + + For more information, refer to the `documentation for pdb + `_ available on the Python + website. + + :param app: the application to wrap. + :param debugger: a callable to start debugging, defaulting to the Python + debugger, ``pdb``. + """ + def __init__(self, app, debugger=pdb.post_mortem): self.app = app self.debugger = debugger