def log_request(handler):
 status = handler.get_status()
 request = handler.request
 if ((status == 304) or ((status < 300) and isinstance(handler, StaticFileHandler))):
  log_method = access_log.debug
 elif (status < 400):
  log_method = access_log.info
 elif (status < 500):
  log_method = access_log.warning
 else:
  log_method = access_log.error
 uri = _scrub_uri(request.uri)
 headers = _scrub_headers(request.headers)
 request_time = (1000.0 * handler.request.request_time())
 user = handler.get_current_user()
 ns = dict(status=status, method=request.method, ip=request.remote_ip, uri=uri, request_time=request_time, user=(user.name if user else ''))
 msg = '{status} {method} {uri} ({user}@{ip}) {request_time:.2f}ms'
 if ((status >= 500) and (status != 502)):
  log_method(json.dumps(headers, indent=2))
 log_method(msg.format(**ns))

def log_request ( handler ) : status = handler . get_status ( ) request = handler . request if ( ( status == 304 ) or ( ( status < 300 ) and isinstance ( handler , StaticFileHandler ) ) ) : log_method = access_log . debug elif ( status < 400 ) : log_method = access_log . info elif ( status < 500 ) : log_method = access_log . warning else : log_method = access_log . error uri = _scrub_uri ( request . uri ) headers = _scrub_headers ( request . headers ) request_time = ( 1000.0 * handler . request . request_time ( ) ) user = handler . get_current_user ( ) ns = dict ( status = status , method = request . method , ip = request . remote_ip , uri = uri , request_time = request_time , user = ( user . name if user else '' ) ) msg = '{status} {method} {uri} ({user}@{ip}) {request_time:.2f}ms' if ( ( status >= 500 ) and ( status != 502 ) ) : log_method ( json . dumps ( headers , indent = 2 ) ) log_method ( msg . format ( ** ns ) )
log a bit more information about each request than tornados default - move static file get success to debug-level - get proxied ip instead of proxy ip - log referer for redirect and failed requests - log user-agent for failed requests .