From 67a3fe87291f020f4ca4b4e95d82388d384c0cc5 Mon Sep 17 00:00:00 2001 From: Steph Torres Date: Wed, 4 Dec 2024 17:20:38 +0000 Subject: [PATCH] [PRMP-1257] reformat log messages --- .../handlers/manage_nrl_pointer_handler.py | 12 ++--- lambdas/services/nrl_api_service.py | 45 ++++++++++--------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/lambdas/handlers/manage_nrl_pointer_handler.py b/lambdas/handlers/manage_nrl_pointer_handler.py index 41bb603bb..405a1989f 100644 --- a/lambdas/handlers/manage_nrl_pointer_handler.py +++ b/lambdas/handlers/manage_nrl_pointer_handler.py @@ -60,13 +60,13 @@ def lambda_handler(event, context): ) logger.info( - f"Create pointer request: Body: {json.loads(document)}," + f"Create pointer request: Body: {json.loads(document)}, \n" + f"RequestURL: {nrl_api_service.endpoint}, \n" + "HTTPVerb: POST, \n" + f"NHS Number: {nrl_message.nhs_number}, \n" + f"ODS code: {nrl_api_service.end_user_ods_code}, \n" + f"Datetime: {int(datetime.now().timestamp())} " ) - logger.info(f"RequestURL: {nrl_api_service.endpoint},") - logger.info("HTTPVerb: POST,") - logger.info(f"NHS Number: {nrl_message.nhs_number},") - logger.info(f"ODS code: {nrl_api_service.end_user_ods_code},") - logger.info(f"Datetime: {int(datetime.now().timestamp())} ") nrl_api_service.create_new_pointer(json.loads(document)) case NrlActionTypes.DELETE: diff --git a/lambdas/services/nrl_api_service.py b/lambdas/services/nrl_api_service.py index 21d6875e3..972a73b40 100644 --- a/lambdas/services/nrl_api_service.py +++ b/lambdas/services/nrl_api_service.py @@ -50,10 +50,11 @@ def create_new_pointer(self, body, retry_on_expired: bool = True): ) response.raise_for_status() logger.info( - f"Create pointer response: Status code: ${response.status_code}" + f"Create pointer response: Status code: ${response.status_code} \n" + f"Body: {response.json()}, \n" + f"Date: ${response.headers.get('date', 'No date found.')}" ) - logger.info(f"Body: {response.json()},") - logger.info(f"Date: ${response.headers.get('date', 'No date found.')}") + logger.info("Successfully created new pointer") except HTTPError as e: logger.error(e.response) @@ -66,12 +67,13 @@ def create_new_pointer(self, body, retry_on_expired: bool = True): raise NrlApiException("Error while creating new NRL Pointer") def get_pointer(self, nhs_number, record_type=None, retry_on_expired: bool = True): - logger.info(f"Get pointer request: URL: {self.endpoint},") - logger.info("HTTP Verb: GET,") - logger.info(f"ODS code: {self.end_user_ods_code},") - logger.info(f"Datetime: {int(datetime.now().timestamp())},") - logger.info(f"UserID: {self.end_user_ods_code},") - + logger.info( + f"Get pointer request: URL: {self.endpoint}, \n" + "HTTP Verb: GET, \n" + f"ODS code: {self.end_user_ods_code}, \n" + f"Datetime: {int(datetime.now().timestamp())}, \n" + f"UserID: {self.end_user_ods_code}, \n" + ) try: self.set_x_request_id() params = { @@ -84,10 +86,11 @@ def get_pointer(self, nhs_number, record_type=None, retry_on_expired: bool = Tru ) response.raise_for_status() - logger.info(f"Get pointer response: Status code: {response.status_code}, ") - logger.info(f"Body: {response.json()},") - logger.info(f"Date: {response.headers.get('date', 'No date found.')}") - + logger.info( + f"Get pointer response: Status code: {response.status_code}, \n" + f"Body: {response.json()}, \n" + f"Date: {response.headers.get('date', 'No date found.')}" + ) return response.json() except HTTPError as e: logger.error(e.response.json()) @@ -106,19 +109,19 @@ def delete_pointer(self, nhs_number, record_type): pointer_id = entry.get("resource", {}).get("id") url_endpoint = self.endpoint + f"/{pointer_id}" logger.info( - f"Delete pointer request: URL: {url_endpoint}, " - f"HTTP Verb: DELETE, " - f"ODS code: {self.end_user_ods_code}, " - f"NHS number: {nhs_number}, " - f"Datetime: {int(datetime.now().timestamp())}, " - f"UserID: {self.end_user_ods_code}" + f"Delete pointer request: URL: {url_endpoint}, \n" + f"HTTP Verb: DELETE, \n" + f"ODS code: {self.end_user_ods_code}, \n" + f"NHS number: {nhs_number}, \n" + f"Datetime: {int(datetime.now().timestamp())}, \n" + f"UserID: {self.end_user_ods_code} \n" ) try: response = self.session.delete(url=url_endpoint, headers=self.headers) response.raise_for_status() logger.info( - f"Delete pointer response: Body: {response.json()}, " - f"Status Code: {response.status_code}, " + f"Delete pointer response: Body: {response.json()}, \n" + f"Status Code: {response.status_code}, \n" f"Date: {response.headers.get('date', 'No date found.')}" ) except HTTPError as e: