Created
July 27, 2015 13:50
-
-
Save mariocesar/858d84b51e0c3a069b78 to your computer and use it in GitHub Desktop.
WSGI Python middleware to simple log all requests and responses to later debug.
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
class RequestLogMiddleware(object): | |
""" | |
Log requests to the application, a simple wsgi middleware. | |
""" | |
def __init__(self, application): | |
self.application = application | |
def __call__ (self, environ, start_response): | |
context = {} | |
self.context['script_name'] = environ.get('HTTP_X_SCRIPT_NAME', '') | |
self.context['errors'] = environ['wsgi.errors'] | |
self.context['url'] = environ['wsgi.url_scheme'] + '://' + environ['HTTP_HOST'] + environ['PATH_INFO'] | |
if environ['QUERY_STRING']: | |
self.context['url'] += '?' + environ['QUERY_STRING'] | |
self.do_log_request(environ, context) | |
response = self.application(environ, start_response) | |
self.do_log_response(start_response, context) | |
return response | |
def do_log_request(self, environ, context): | |
pass | |
def do_log_response(self, response, context): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment