Skip to content

Instantly share code, notes, and snippets.

@felipecruz
Created February 23, 2011 19:56
Show Gist options
  • Save felipecruz/841038 to your computer and use it in GitHub Desktop.
Save felipecruz/841038 to your computer and use it in GitHub Desktop.
# Original WSGI application.
def application(environ, start_response):
...
# Logging WSGI middleware.
import pprint
class LoggingMiddleware:
def __init__(self, application):
self.__application = application
def __call__(self, environ, start_response):
errors = environ['wsgi.errors']
pprint.pprint(('REQUEST', environ), stream=errors)
def _start_response(status, headers):
pprint.pprint(('RESPONSE', status, headers), stream=errors)
return start_response(status, headers)
return self.__application(environ, _start_response)
application = LoggingMiddleware(application)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment