diff --git a/config-example.yml b/config-example.yml index 3cb1822..2c48dc7 100644 --- a/config-example.yml +++ b/config-example.yml @@ -211,6 +211,10 @@ clublog-api-key: "" # Allow submitting spots to the Spothole API? allow-spotting: true +# Log web requests? Useful to see what your users are requesting in terms of pages and API endpoints, but will fill up +# your log quickly on a popular server. +log-web-requests: false + # Options for the web UI. web-ui-options: spot-count: [ 10, 25, 50, 100 ] diff --git a/core/config.py b/core/config.py index 70adc18..ff0f235 100644 --- a/core/config.py +++ b/core/config.py @@ -22,6 +22,7 @@ WEB_SERVER_PORT = config["web-server-port"] ALLOW_SPOTTING = config["allow-spotting"] WEB_UI_OPTIONS = config["web-ui-options"] API_ONLY_MODE = config.get("api-only-mode", False) +LOG_WEB_REQUESTS = config.get("log-web-requests", False) # For ease of config, each spot provider owns its own config about whether it should be enabled by default in the web UI # but for consistency we provide this to the front-end in web-ui-options because it has no impact outside of the web UI. diff --git a/server/webserver.py b/server/webserver.py index bf846ec..a99030c 100644 --- a/server/webserver.py +++ b/server/webserver.py @@ -5,7 +5,7 @@ import os import tornado from tornado.web import StaticFileHandler -from core.config import ALLOW_SPOTTING, WEB_SERVER_PORT, API_ONLY_MODE +from core.config import ALLOW_SPOTTING, WEB_SERVER_PORT, API_ONLY_MODE, LOG_WEB_REQUESTS from core.utils import empty_queue from server.handlers.api.addspot import APISpotHandler from server.handlers.api.alerts import APIAlertsHandler, APIAlertsStreamHandler @@ -165,20 +165,22 @@ class WebServer: pass def request_log(handler): - """Custom log function to provide more data about requests.""" + """Custom log function to provide more data about requests when enabled, and to provide the ability to turn off + web request logging altogetether.""" - if handler.get_status() < 500: - log_method = logging.info - else: - log_method = logging.warning + if LOG_WEB_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", "-") + 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}' - ) + log_method( + f'{client_ip} - "{request.method} {request.uri}" ' + f'{handler.get_status()} {request.request_time():.2f}ms | ' + f'Ref: {referrer} | UA: {user_agent}' + ) diff --git a/templates/add_spot.html b/templates/add_spot.html index 69ce837..9a4de26 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -76,7 +76,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index 74ce1fb..1064f3e 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -75,7 +75,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index f0e7c39..235e97f 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -75,8 +75,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index 0874163..455d4d4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -10,10 +10,10 @@ - - - - + + + + {% end %} {% block body %}
diff --git a/templates/conditions.html b/templates/conditions.html index 3b81962..c4cd2b3 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -284,7 +284,7 @@
- + diff --git a/templates/map.html b/templates/map.html index fede4f6..a684034 100644 --- a/templates/map.html +++ b/templates/map.html @@ -95,8 +95,8 @@ - - + + diff --git a/templates/spots.html b/templates/spots.html index d4073d5..4ba5ca6 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -116,8 +116,8 @@ - - + + diff --git a/templates/status.html b/templates/status.html index 7a3c2be..4490070 100644 --- a/templates/status.html +++ b/templates/status.html @@ -59,7 +59,7 @@ - +