Skip to content

Commit

Permalink
Added log_reqest method to HttpServer to demote request logging to de…
Browse files Browse the repository at this point in the history
…bug level
  • Loading branch information
timcnicholls committed Nov 22, 2016
1 parent 6b0b3d0 commit cf4e3e3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions odin/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tornado.gen
import tornado.web
import tornado.ioloop
from tornado.log import access_log

from odin.http.routes.api import ApiRoute
from odin.http.routes.default import DefaultRoute
Expand All @@ -26,6 +27,7 @@ def __init__(self, debug_mode=False, static_path='./static', adapters=None):
"""
settings = {
"debug": debug_mode,
"log_function": self.log_request,
}

# Create an API route
Expand All @@ -52,6 +54,26 @@ def listen(self, port, host=''):
"""
self.application.listen(port, host)

def log_request(self, handler):
"""Log completed request information.
This method is passed to the tornado.web.Application instance to override the
default request logging behaviour. In doing so, successful requests are logged
at debug level rather than info in order to reduce the rate of logging under
normal conditions.
:param handler: currently active request handler
"""
if handler.get_status() < 400:
log_method = access_log.debug
elif handler.get_status() < 500:
log_method = access_log.warning
else:
log_method = access_log.error
request_time = 1000.0 * handler.request.request_time()
log_method("%d %s %.2fms", handler.get_status(),
handler._request_summary(), request_time)

def cleanup_adapters(self):
"""Clean up state of registered adapters.
"""
Expand Down

0 comments on commit cf4e3e3

Please sign in to comment.