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:
Ian Renton
2026-06-20 12:17:13 +01:00
parent 92121d7953
commit 5c598f91e6
11 changed files with 79 additions and 23 deletions

View File

@@ -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}'
)