mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-06-23 21:25:12 +00:00
Pass through more info from nginx and log it, to help me figure out who's using Spothole and contact them about upcoming API changes. Also an enabler for #101.
This commit is contained in:
@@ -108,8 +108,9 @@ class WebServer:
|
||||
|
||||
app = tornado.web.Application(api_routes + ui_routes + misc_routes,
|
||||
template_path=os.path.join(_HERE, "../templates"),
|
||||
log_function=request_log,
|
||||
debug=False)
|
||||
app.listen(self._port)
|
||||
app.listen(self._port, xheaders=True)
|
||||
logging.info("Web server running on port " + str(WEB_SERVER_PORT))
|
||||
await self._shutdown_event.wait()
|
||||
|
||||
@@ -162,3 +163,22 @@ class WebServer:
|
||||
# Probably got deleted already on another thread
|
||||
pass
|
||||
pass
|
||||
|
||||
def request_log(handler):
|
||||
"""Custom log function to provide more data about requests."""
|
||||
|
||||
if handler.get_status() < 500:
|
||||
log_method = logging.info
|
||||
else:
|
||||
log_method = logging.warning
|
||||
|
||||
request = handler.request
|
||||
client_ip = request.remote_ip
|
||||
referrer = request.headers.get("Referer", "-")
|
||||
user_agent = request.headers.get("User-Agent", "-")
|
||||
|
||||
log_method(
|
||||
f'{client_ip} - "{request.method} {request.uri}" '
|
||||
f'{handler.get_status()} {request.request_time():.2f}ms | '
|
||||
f'Ref: {referrer} | UA: {user_agent}'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user