Skip to content

Instantly share code, notes, and snippets.

@MaikuMori
Forked from jaytaylor/serving.py
Last active December 23, 2015 05:09
Show Gist options
  • Save MaikuMori/6585167 to your computer and use it in GitHub Desktop.
Save MaikuMori/6585167 to your computer and use it in GitHub Desktop.
TimedRequestHandler
import time
from werkzeug.serving import WSGIRequestHandler
class TimedRequestHandler(WSGIRequestHandler):
"""
Add request time info to logs.
"""
def handle(self):
self.start = time.clock()
rv = super(TimedRequestHandler, self).handle()
return rv
def send_response(self, *args, **kw):
self.end = time.clock()
super(TimedRequestHandler, self).send_response(*args, **kw)
def log_request(self, code='-', size='-'):
duration = int((self.end - self.start) * 1000)
self.log('info', '"%s" %s %s [%sms]', self.requestline, code, size, duration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment