Created
February 23, 2011 19:56
-
-
Save felipecruz/841038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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