Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
def log_request(self, handler):
log = logging.getLogger('demo')
log.setLevel(logging.DEBUG)
log.addHandler(MongoHandler.to(db='mongolog', collection='log', host='db.example.com'))
if handler.get_status() < 400:
log_method = log.info
elif handler.get_status() < 500:
log_method = log.warn
else:
log_method = log.error
request_time = 1000.0 * handler.request.request_time()
log_message = '%d %s %.2fms' % (handler.get_status(), handler._request_summary(), request_time)
log_method(log_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment