Skip to content

Instantly share code, notes, and snippets.

@joet3ch
Created November 2, 2011 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joet3ch/1332516 to your computer and use it in GitHub Desktop.
Save joet3ch/1332516 to your computer and use it in GitHub Desktop.
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