From 5ad5746adb376a25b2fc9e74438fa08ec745f906 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 8 Mar 2024 11:07:28 +0100 Subject: [PATCH 1/5] Add logging of requests --- narrowcast_content/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/narrowcast_content/__init__.py b/narrowcast_content/__init__.py index 99ce427..2747313 100644 --- a/narrowcast_content/__init__.py +++ b/narrowcast_content/__init__.py @@ -69,3 +69,9 @@ def check_auth(): if session['token'] not in tokens: abort(401, "Unauthorized") + +@app.after_request +def after_request(response): + timestamp = strftime('[%Y-%b-%d %H:%M]') + logger.error('%s %s %s %s %s %s', timestamp, request.remote_addr, request.method, request.scheme, request.full_path, response.status) + return response From e2c7f6ee40f76ba7e63dd0994db68815e8314b14 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 8 Mar 2024 11:11:00 +0100 Subject: [PATCH 2/5] Add datetime --- narrowcast_content/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/narrowcast_content/__init__.py b/narrowcast_content/__init__.py index 2747313..4e7938a 100644 --- a/narrowcast_content/__init__.py +++ b/narrowcast_content/__init__.py @@ -1,5 +1,6 @@ import logging from logging import Formatter, FileHandler +from datetime import datetime from flask import Flask, request, abort, session @@ -72,6 +73,6 @@ def check_auth(): @app.after_request def after_request(response): - timestamp = strftime('[%Y-%b-%d %H:%M]') + timestamp = datetime.now().strftime('[%Y-%b-%d %H:%M]') logger.error('%s %s %s %s %s %s', timestamp, request.remote_addr, request.method, request.scheme, request.full_path, response.status) return response From 0d1d2d6a3db176e302ac9bd9aabbfeed7fb4d122 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 8 Mar 2024 11:55:58 +0100 Subject: [PATCH 3/5] Add logging --- Dockerfile | 2 +- narrowcast_content/waitress_server.py | 5 +++++ pyproject.toml | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 narrowcast_content/waitress_server.py diff --git a/Dockerfile b/Dockerfile index 3fae0fb..f518831 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,4 @@ RUN pip install . EXPOSE 8080 -CMD [ "waitress-serve", "narrowcast_content:app"] \ No newline at end of file +CMD [ "python", "-m", "narrowcast_content.waitress_server"] \ No newline at end of file diff --git a/narrowcast_content/waitress_server.py b/narrowcast_content/waitress_server.py new file mode 100644 index 0000000..be38479 --- /dev/null +++ b/narrowcast_content/waitress_server.py @@ -0,0 +1,5 @@ +from waitress import serve +from . import app +from paste.translogger import TransLogger + +serve(TransLogger(app, setup_console_handler=False), host='0.0.0.0', port=8080) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index f5cae06..bb7ff99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,8 @@ dependencies = [ "spotipy", "icalendar", "waitress", + "PasteDeploy", + "paste", ] [build-system] From 09b6436d28f1eb0d11c1c434d177c6bb354b6083 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 8 Mar 2024 11:57:47 +0100 Subject: [PATCH 4/5] Remove old logging --- narrowcast_content/__init__.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/narrowcast_content/__init__.py b/narrowcast_content/__init__.py index 4e7938a..99ce427 100644 --- a/narrowcast_content/__init__.py +++ b/narrowcast_content/__init__.py @@ -1,6 +1,5 @@ import logging from logging import Formatter, FileHandler -from datetime import datetime from flask import Flask, request, abort, session @@ -70,9 +69,3 @@ def check_auth(): if session['token'] not in tokens: abort(401, "Unauthorized") - -@app.after_request -def after_request(response): - timestamp = datetime.now().strftime('[%Y-%b-%d %H:%M]') - logger.error('%s %s %s %s %s %s', timestamp, request.remote_addr, request.method, request.scheme, request.full_path, response.status) - return response From 20cee0af166f1965aede7600606c7b0c256b5644 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 8 Mar 2024 12:08:01 +0100 Subject: [PATCH 5/5] Increase waitress limits --- narrowcast_content/waitress_server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/narrowcast_content/waitress_server.py b/narrowcast_content/waitress_server.py index be38479..f87b69f 100644 --- a/narrowcast_content/waitress_server.py +++ b/narrowcast_content/waitress_server.py @@ -2,4 +2,9 @@ from . import app from paste.translogger import TransLogger -serve(TransLogger(app, setup_console_handler=False), host='0.0.0.0', port=8080) \ No newline at end of file +serve(TransLogger(app, setup_console_handler=False), + host='0.0.0.0', + port=8080, + connection_limit=500, + threads=8, + ) \ No newline at end of file