From c78bbb9e2a46c1a3606fba7f76b888cddfb497e2 Mon Sep 17 00:00:00 2001 From: Colin B Date: Fri, 29 Nov 2024 16:51:36 +0000 Subject: [PATCH 01/22] update logger config to json format --- app/logger_config.py | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index 99cc093b..975a278b 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -1,17 +1,26 @@ import logging +import json from flask import has_request_context, request class RequestFormatter(logging.Formatter): def format(self, record): + log_record = { + "log_type": record.name, + "timestamp": self.formatTime(record), + "level": record.levelname, + "message": record.getMessage(), + "module": record.module, + } + if has_request_context(): - record.url = request.url - record.remote_addr = request.remote_addr - else: - record.url = None - record.remote_addr = None - return super().format(record) + log_record.update({ + "remote_addr": request.remote_addr, + "url": request.url, + }) + + return json.dumps(log_record) def setup_logger(name, level, formatter): @@ -26,18 +35,8 @@ def setup_logger(name, level, formatter): def setup_logging(app): """Set up loggers for the app.""" - audit_log_formatter = RequestFormatter( - "AUDIT_LOG\n" - "[%(asctime)s] %(remote_addr)s requested %(url)s\n" - "%(levelname)s in %(module)s: %(message)s" - ) - app.audit_logger = setup_logger( - "audit_logger", logging.INFO, audit_log_formatter - ) - - app_log_formatter = RequestFormatter( - "APP_LOG\n" - "[%(asctime)s] %(remote_addr)s requested %(url)s\n" - "%(levelname)s in %(module)s: %(message)s" - ) - app.app_logger = setup_logger("app_logger", logging.INFO, app_log_formatter) + audit_log_formatter = RequestFormatter() + app.audit_logger = setup_logger("audit_logger", logging.INFO, audit_log_formatter) + + app_log_formatter = RequestFormatter() + app.app_logger = setup_logger("app_logger", logging.INFO, app_log_formatter) \ No newline at end of file From 972dc9914e653fe1bb61167fffbfa7c048154695 Mon Sep 17 00:00:00 2001 From: Colin B Date: Fri, 29 Nov 2024 16:56:40 +0000 Subject: [PATCH 02/22] pre commit new line --- app/logger_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logger_config.py b/app/logger_config.py index 975a278b..e9dacb60 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -39,4 +39,4 @@ def setup_logging(app): app.audit_logger = setup_logger("audit_logger", logging.INFO, audit_log_formatter) app_log_formatter = RequestFormatter() - app.app_logger = setup_logger("app_logger", logging.INFO, app_log_formatter) \ No newline at end of file + app.app_logger = setup_logger("app_logger", logging.INFO, app_log_formatter) From eeaf6eee0101f55276ce0d88e2d8c8ed4d3bb3b8 Mon Sep 17 00:00:00 2001 From: Colin B Date: Mon, 2 Dec 2024 13:50:01 +0000 Subject: [PATCH 03/22] pre commit --- app/logger_config.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index e9dacb60..467f73ce 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -1,5 +1,5 @@ -import logging import json +import logging from flask import has_request_context, request @@ -15,10 +15,12 @@ def format(self, record): } if has_request_context(): - log_record.update({ - "remote_addr": request.remote_addr, - "url": request.url, - }) + log_record.update( + { + "remote_addr": request.remote_addr, + "url": request.url, + } + ) return json.dumps(log_record) @@ -36,7 +38,9 @@ def setup_logger(name, level, formatter): def setup_logging(app): """Set up loggers for the app.""" audit_log_formatter = RequestFormatter() - app.audit_logger = setup_logger("audit_logger", logging.INFO, audit_log_formatter) + app.audit_logger = setup_logger( + "audit_logger", logging.INFO, audit_log_formatter + ) app_log_formatter = RequestFormatter() app.app_logger = setup_logger("app_logger", logging.INFO, app_log_formatter) From 29a0851a426af8de863fbbe6ff676ecbb101b672 Mon Sep 17 00:00:00 2001 From: Colin B Date: Mon, 2 Dec 2024 15:52:07 +0000 Subject: [PATCH 04/22] update log message --- app/logger_config.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/logger_config.py b/app/logger_config.py index 467f73ce..e7208a53 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -22,6 +22,15 @@ def format(self, record): } ) + try: + message_data = json.loads(record.getMessage()) + if isinstance(message_data, dict): + log_record.update(message_data) + else: + log_record["message"] = message_data + except json.JSONDecodeError: + log_record["message"] = record.getMessage() + return json.dumps(log_record) From 2fe678b80ac8d46f69bcaa796674ee6b7332c166 Mon Sep 17 00:00:00 2001 From: Colin B Date: Thu, 5 Dec 2024 13:50:03 +0000 Subject: [PATCH 05/22] rem message from audit log --- app/logger_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/logger_config.py b/app/logger_config.py index e7208a53..62c01649 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -10,7 +10,6 @@ def format(self, record): "log_type": record.name, "timestamp": self.formatTime(record), "level": record.levelname, - "message": record.getMessage(), "module": record.module, } From 7fad34eafe7a4182ee439ff2d323bd0e5655eb69 Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 11:13:47 +0000 Subject: [PATCH 06/22] add func name, line number --- app/logger_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/logger_config.py b/app/logger_config.py index 62c01649..73de0190 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -11,6 +11,8 @@ def format(self, record): "timestamp": self.formatTime(record), "level": record.levelname, "module": record.module, + "function": record.funcName, + "line_number": record.lineno, } if has_request_context(): From dbb40e27f56265fb23068b0f88fefe5a28845f87 Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 11:39:13 +0000 Subject: [PATCH 07/22] get func name --- app/logger_config.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/logger_config.py b/app/logger_config.py index 73de0190..53d00698 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -1,3 +1,4 @@ +import inspect import json import logging @@ -11,7 +12,7 @@ def format(self, record): "timestamp": self.formatTime(record), "level": record.levelname, "module": record.module, - "function": record.funcName, + "function": self.get_original_function_name(record), "line_number": record.lineno, } @@ -34,6 +35,12 @@ def format(self, record): return json.dumps(log_record) + def get_original_function_name(self, record): + for frame in inspect.stack(): + if frame.function == record.funcName: + return frame.function + return record.funcName + def setup_logger(name, level, formatter): """Helper function to set up a logger.""" From 1f3b867361c77ddd4551a7f29a1db1d003ef9a93 Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 14:06:19 +0000 Subject: [PATCH 08/22] check stack frame --- app/logger_config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index 53d00698..46591c79 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -35,11 +35,14 @@ def format(self, record): return json.dumps(log_record) - def get_original_function_name(self, record): - for frame in inspect.stack(): - if frame.function == record.funcName: - return frame.function - return record.funcName + def get_calling_function_name(self, record): + if record.stack_info: + stack_frames = inspect.extract_stack(record.stack_info) + if len(stack_frames) > 1: + # The second frame is the calling function + calling_frame = stack_frames[-2] + return calling_frame.function + return None def setup_logger(name, level, formatter): From a84d9487d239a2accfaf06f048c36be4ccafbc98 Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 14:12:49 +0000 Subject: [PATCH 09/22] fix func name --- app/logger_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logger_config.py b/app/logger_config.py index 46591c79..1d9052eb 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -12,7 +12,7 @@ def format(self, record): "timestamp": self.formatTime(record), "level": record.levelname, "module": record.module, - "function": self.get_original_function_name(record), + "function": self.get_calling_function_name(record), "line_number": record.lineno, } From 06b8e10404a63a1600271a767b87d43eb722a71f Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 15:34:34 +0000 Subject: [PATCH 10/22] add print --- app/logger_config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/logger_config.py b/app/logger_config.py index 1d9052eb..6e825dc1 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -38,6 +38,7 @@ def format(self, record): def get_calling_function_name(self, record): if record.stack_info: stack_frames = inspect.extract_stack(record.stack_info) + print("STACK FRAMES", stack_frames) if len(stack_frames) > 1: # The second frame is the calling function calling_frame = stack_frames[-2] From f7f68492b93d055638c52169b44577ee25387970 Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 17:38:08 +0000 Subject: [PATCH 11/22] addd caller to log --- app/logger_config.py | 11 ----------- app/main/middlewares/log_page_view.py | 2 ++ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index 6e825dc1..5f6ad1ec 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -12,7 +12,6 @@ def format(self, record): "timestamp": self.formatTime(record), "level": record.levelname, "module": record.module, - "function": self.get_calling_function_name(record), "line_number": record.lineno, } @@ -35,16 +34,6 @@ def format(self, record): return json.dumps(log_record) - def get_calling_function_name(self, record): - if record.stack_info: - stack_frames = inspect.extract_stack(record.stack_info) - print("STACK FRAMES", stack_frames) - if len(stack_frames) > 1: - # The second frame is the calling function - calling_frame = stack_frames[-2] - return calling_frame.function - return None - def setup_logger(name, level, formatter): """Helper function to set up a logger.""" diff --git a/app/main/middlewares/log_page_view.py b/app/main/middlewares/log_page_view.py index 29179d38..491b52c3 100644 --- a/app/main/middlewares/log_page_view.py +++ b/app/main/middlewares/log_page_view.py @@ -13,6 +13,8 @@ def wrapper(*args, **kwargs): "user_id": user_id, "route": request.url, "method": request.method, + "caller_function": route_function.__name__, + "caller_module": route_function.__module__, } current_app.audit_logger.info(json.dumps(log_data)) return route_function(*args, **kwargs) From 7179983b794d80ad695a868cabc32ba05e756a16 Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 17:46:25 +0000 Subject: [PATCH 12/22] pre commit --- app/logger_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/logger_config.py b/app/logger_config.py index 5f6ad1ec..0d925ae1 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -1,4 +1,3 @@ -import inspect import json import logging From ee122f0d3c88820af6a584a03a99026af86b182c Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 17:53:15 +0000 Subject: [PATCH 13/22] rem sec log module --- app/logger_config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index 0d925ae1..b682cc63 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -10,8 +10,6 @@ def format(self, record): "log_type": record.name, "timestamp": self.formatTime(record), "level": record.levelname, - "module": record.module, - "line_number": record.lineno, } if has_request_context(): From 9b39f86cd2ea3a05be430360d0d6d1f6f866e4f0 Mon Sep 17 00:00:00 2001 From: Colin B Date: Tue, 10 Dec 2024 18:18:44 +0000 Subject: [PATCH 14/22] update tests --- app/tests/test_middlewares.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/tests/test_middlewares.py b/app/tests/test_middlewares.py index e24d3b6e..66b27d73 100644 --- a/app/tests/test_middlewares.py +++ b/app/tests/test_middlewares.py @@ -1,3 +1,5 @@ +import json + import pytest from flask.testing import FlaskClient from moto import mock_aws @@ -16,7 +18,10 @@ {"user_id": "test_user"}, lambda: "Test Response", b"Test Response", - f'{{"event": "api_request", "user_id": "test_user", "route": "{HOST}/test_route", "method": "GET"}}', + json.loads( + """{"event": "api_request", "user_id": "test_user", "route": "http://localhost/test_route", + "method": "GET", "caller_function": "dynamic_route", "caller_module": "app.tests.test_middlewares"}""" + ), ), ( "/anonymous_route", @@ -24,7 +29,10 @@ {}, lambda: "Anonymous Response", b"Anonymous Response", - f'{{"event": "api_request", "user_id": "anonymous", "route": "{HOST}/anonymous_route", "method": "GET"}}', + json.loads( + """{"event": "api_request", "user_id": "anonymous", "route": "http://localhost/anonymous_route", + "method": "GET", "caller_function": "dynamic_route", "caller_module": "app.tests.test_middlewares"}""" + ), ), ( "/post_route", @@ -32,7 +40,10 @@ {"user_id": "test_user"}, lambda: "Post Response", b"Post Response", - f'{{"event": "api_request", "user_id": "test_user", "route": "{HOST}/post_route", "method": "POST"}}', + json.loads( + """{"event": "api_request", "user_id": "test_user", "route": "http://localhost/post_route", + "method": "POST", "caller_function": "dynamic_route", "caller_module": "app.tests.test_middlewares"}""" + ), ), ], ) @@ -48,9 +59,6 @@ def test_log_page_view( expected_log, caplog, ): - """Test that the log_page_view middleware generates the correct log when an - endpoint decorated with it is requested""" - @app.route(route_path, methods=[method]) @log_page_view def dynamic_route(): @@ -64,5 +72,6 @@ def dynamic_route(): assert response.status_code == 200 assert response.data == expected_response + logged_message = json.loads(caplog.records[0].message) assert caplog.records[0].levelname == "INFO" - assert caplog.records[0].message == expected_log + assert logged_message == expected_log From b27a69915ef6ee8d8d23f13787848d15c11b6db9 Mon Sep 17 00:00:00 2001 From: Colin B Date: Wed, 11 Dec 2024 12:49:59 +0000 Subject: [PATCH 15/22] update readme --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 8912f04e..c053fcf9 100644 --- a/README.md +++ b/README.md @@ -630,7 +630,42 @@ current_app.audit_logger.error('Some error message') The logs from the webapp, when used as above are output as a stream to stdout in the following format: +LOG ENTRY for a page view using the @log_page_view decorator: + ```sh +START RequestId: 4e2b263b-fc27-4db2-b87e-867fc4596e69 Version: $LATEST + +[DEBUG] 2024-12-11T12:43:26.106Z 4e2b263b-fc27-4db2-b87e-867fc4596e69 host found: [test-one.np.ayr.nationalarchives.gov.uk] + +{ + "log_type": "audit_logger", + "timestamp": "2024-12-11 12:43:26,106", + "level": "INFO", + "remote_addr": "13.42.156.7", + "url": "https://test-one.np.ayr.nationalarchives.gov.uk/callback?code=24a260d2-b142-4db5-8675-c2acddcb7e7f.2d9cb0a3-8ce0-400a-afa9-c13298eb33ac.29a32c8f-97d2-4680-b58e-ac9120a4f94d&iss=https://auth.tdr-staging.nationalarchives.gov.uk/realms/tdr&session_state=2d9cb0a3-8ce0-400a-afa9-c13298eb33ac&state=", + "event": "api_request", + "user_id": "anonymous", + "route": "/callback", + "method": "GET", + "caller_function": "callback", + "caller_module": "app.main.routes" +} + +{ + "event": "api_request", + "user_id": "anonymous", + "route": "/callback", + "method": "GET", + "caller_function": "callback", + "caller_module": "app.main.routes" +} + + +END RequestId: 4e2b263b-fc27-4db2-b87e-867fc4596e69 +``` + +LOG ENTRY for an Error +``` [2023-12-15 15:40:14,119] 127.0.0.1 requested https://localhost:5000/logger_test?log_level=error ERROR in routes: Some error ``` From c754df25ab6dbfeec23cc628916e1f22f6b3c2dd Mon Sep 17 00:00:00 2001 From: Colin B Date: Wed, 11 Dec 2024 16:06:24 +0000 Subject: [PATCH 16/22] remove urls --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c053fcf9..fcd0061e 100644 --- a/README.md +++ b/README.md @@ -635,14 +635,14 @@ LOG ENTRY for a page view using the @log_page_view decorator: ```sh START RequestId: 4e2b263b-fc27-4db2-b87e-867fc4596e69 Version: $LATEST -[DEBUG] 2024-12-11T12:43:26.106Z 4e2b263b-fc27-4db2-b87e-867fc4596e69 host found: [test-one.np.ayr.nationalarchives.gov.uk] +[DEBUG] 2024-12-11T12:43:26.106Z 4e2b263b-fc27-4db2-b87e-867fc4596e69 host found: [test-url] { "log_type": "audit_logger", "timestamp": "2024-12-11 12:43:26,106", "level": "INFO", "remote_addr": "13.42.156.7", - "url": "https://test-one.np.ayr.nationalarchives.gov.uk/callback?code=24a260d2-b142-4db5-8675-c2acddcb7e7f.2d9cb0a3-8ce0-400a-afa9-c13298eb33ac.29a32c8f-97d2-4680-b58e-ac9120a4f94d&iss=https://auth.tdr-staging.nationalarchives.gov.uk/realms/tdr&session_state=2d9cb0a3-8ce0-400a-afa9-c13298eb33ac&state=", + "url": "test-url", "event": "api_request", "user_id": "anonymous", "route": "/callback", From eaf127f93da11698b55e16a5ef53d110dae86b27 Mon Sep 17 00:00:00 2001 From: Colin B Date: Wed, 11 Dec 2024 17:37:38 +0000 Subject: [PATCH 17/22] move func and module to upper audit logger --- app/logger_config.py | 18 ++++++++++++++++++ app/main/middlewares/log_page_view.py | 2 -- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index b682cc63..c1f587dd 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -1,3 +1,4 @@ +import inspect import json import logging @@ -6,17 +7,34 @@ class RequestFormatter(logging.Formatter): def format(self, record): + log_record = { "log_type": record.name, "timestamp": self.formatTime(record), "level": record.levelname, } + caller_function = "" + caller_module = "" + + for frame in inspect.stack(): + if "app.logger_config" not in str( + frame.frame.f_globals.get("__name__") + ): + if "app." in str(frame.frame.f_globals.get("__name__")): + caller_function = frame.function + caller_module = frame.frame.f_globals.get( + "__name__", "unknown" + ) + break + if has_request_context(): log_record.update( { "remote_addr": request.remote_addr, "url": request.url, + "caller_function": caller_function, + "caller_module": caller_module, } ) diff --git a/app/main/middlewares/log_page_view.py b/app/main/middlewares/log_page_view.py index 491b52c3..29179d38 100644 --- a/app/main/middlewares/log_page_view.py +++ b/app/main/middlewares/log_page_view.py @@ -13,8 +13,6 @@ def wrapper(*args, **kwargs): "user_id": user_id, "route": request.url, "method": request.method, - "caller_function": route_function.__name__, - "caller_module": route_function.__module__, } current_app.audit_logger.info(json.dumps(log_data)) return route_function(*args, **kwargs) From 105dbac7ede67c57f538f3852aa6f15abf577494 Mon Sep 17 00:00:00 2001 From: Colin B Date: Wed, 11 Dec 2024 17:38:11 +0000 Subject: [PATCH 18/22] pre commit --- app/logger_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logger_config.py b/app/logger_config.py index c1f587dd..b7ff8381 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -24,7 +24,7 @@ def format(self, record): if "app." in str(frame.frame.f_globals.get("__name__")): caller_function = frame.function caller_module = frame.frame.f_globals.get( - "__name__", "unknown" + "__name__", "" ) break From 763161c3b5e5bf90f9a8bec7a469a62f6bd13335 Mon Sep 17 00:00:00 2001 From: Colin B Date: Wed, 11 Dec 2024 17:39:18 +0000 Subject: [PATCH 19/22] pre commit --- app/logger_config.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index b7ff8381..741ff8c3 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -23,9 +23,7 @@ def format(self, record): ): if "app." in str(frame.frame.f_globals.get("__name__")): caller_function = frame.function - caller_module = frame.frame.f_globals.get( - "__name__", "" - ) + caller_module = frame.frame.f_globals.get("__name__", "") break if has_request_context(): From 490eb04f64fb5e3e4029359a0d9b03a3edd82f10 Mon Sep 17 00:00:00 2001 From: Colin B Date: Wed, 11 Dec 2024 17:54:10 +0000 Subject: [PATCH 20/22] exclude middleware --- app/logger_config.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index 741ff8c3..1c86ff0a 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -18,12 +18,14 @@ def format(self, record): caller_module = "" for frame in inspect.stack(): - if "app.logger_config" not in str( - frame.frame.f_globals.get("__name__") + module_name = str(frame.frame.f_globals.get("__name__", "")) + if ( + "app.logger_config" not in module_name + and "app.main.middlewares.log_page_view" not in module_name ): - if "app." in str(frame.frame.f_globals.get("__name__")): + if "app." in module_name: caller_function = frame.function - caller_module = frame.frame.f_globals.get("__name__", "") + caller_module = module_name break if has_request_context(): From 492f6ec11ce5cebe3419e9004612dd597d5ede97 Mon Sep 17 00:00:00 2001 From: Colin B Date: Thu, 12 Dec 2024 15:26:33 +0000 Subject: [PATCH 21/22] allow log_page_view --- app/logger_config.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/logger_config.py b/app/logger_config.py index 1c86ff0a..903e7cf4 100644 --- a/app/logger_config.py +++ b/app/logger_config.py @@ -19,10 +19,7 @@ def format(self, record): for frame in inspect.stack(): module_name = str(frame.frame.f_globals.get("__name__", "")) - if ( - "app.logger_config" not in module_name - and "app.main.middlewares.log_page_view" not in module_name - ): + if "app.logger_config" not in module_name: if "app." in module_name: caller_function = frame.function caller_module = module_name From e8ff1ed4de7f5544edb2449c4d069a499b9ecac0 Mon Sep 17 00:00:00 2001 From: Colin B Date: Thu, 12 Dec 2024 15:48:05 +0000 Subject: [PATCH 22/22] tests --- app/tests/test_middlewares.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/tests/test_middlewares.py b/app/tests/test_middlewares.py index 66b27d73..4b333632 100644 --- a/app/tests/test_middlewares.py +++ b/app/tests/test_middlewares.py @@ -20,7 +20,7 @@ b"Test Response", json.loads( """{"event": "api_request", "user_id": "test_user", "route": "http://localhost/test_route", - "method": "GET", "caller_function": "dynamic_route", "caller_module": "app.tests.test_middlewares"}""" + "method": "GET"}""" ), ), ( @@ -31,7 +31,7 @@ b"Anonymous Response", json.loads( """{"event": "api_request", "user_id": "anonymous", "route": "http://localhost/anonymous_route", - "method": "GET", "caller_function": "dynamic_route", "caller_module": "app.tests.test_middlewares"}""" + "method": "GET"}""" ), ), ( @@ -42,7 +42,7 @@ b"Post Response", json.loads( """{"event": "api_request", "user_id": "test_user", "route": "http://localhost/post_route", - "method": "POST", "caller_function": "dynamic_route", "caller_module": "app.tests.test_middlewares"}""" + "method": "POST"}""" ), ), ],