Skip to content

Commit

Permalink
Merge pull request #24 from odin-detector/access_logging
Browse files Browse the repository at this point in the history
Add ability to set tornado access log level independently
  • Loading branch information
timcnicholls authored May 10, 2018
2 parents b1603f5 + 0c8f3a1 commit f7ba862
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion odin/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Tim Nicholls, STFC Application Engineering
"""
import logging
import tornado.gen
import tornado.web
import tornado.ioloop
Expand All @@ -18,7 +19,8 @@
class HttpServer(object):
"""HTTP server class."""

def __init__(self, debug_mode=False, static_path='./static', adapters=None):
def __init__(self, debug_mode=False, access_logging=None,
static_path='./static', adapters=None):
"""Initialise the HttpServer object.
:param debug_mode: Set True to enable Tornado debug mode
Expand All @@ -30,6 +32,16 @@ def __init__(self, debug_mode=False, static_path='./static', adapters=None):
"log_function": self.log_request,
}

# Set the up the access log level
if access_logging is not None:
try:
level_val = getattr(logging, access_logging.upper())
access_log.setLevel(level_val)
except AttributeError:
logging.error(
"Access level logging level {} not recognised".format(access_logging)
)

# Create an API route
self.api_route = ApiRoute()

Expand Down
8 changes: 6 additions & 2 deletions odin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def main(argv=None):
config.define('http_addr', default='0.0.0.0', option_help='Set HTTP server address')
config.define('http_port', default=8888, option_help='Set HTTP server port')
config.define('debug_mode', default=False, option_help='Enable tornado debug mode')
config.define('access_logging', default=None, option_help="Set the tornado access log level",
metavar="debug|info|warning|error|none")
config.define('static_path', default='./static', option_help='Set path for static file content')

# Parse configuration options and any configuration file specified
Expand All @@ -63,7 +65,8 @@ def main(argv=None):
logging.info('Using the %s IOLoop instance', '0MQ' if using_zmq_loop else 'tornado')

# Launch the HTTP server
http_server = HttpServer(config.debug_mode, config.static_path, adapters)
http_server = HttpServer(config.debug_mode, config.access_logging,
config.static_path, adapters)
http_server.listen(config.http_port, config.http_addr)

logging.info('HTTP server listening on %s:%s', config.http_addr, config.http_port)
Expand All @@ -77,10 +80,11 @@ def main(argv=None):

# At shutdown, clean up the state of the loaded adapters
http_server.cleanup_adapters()

logging.info('ODIN server shutdown')

return 0


if __name__ == '__main__': # pragma: no cover
sys.exit(main())

0 comments on commit f7ba862

Please sign in to comment.