Skip to content

Commit

Permalink
[PRMP-1257] reformat log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
steph-torres-nhs committed Dec 4, 2024
1 parent b338017 commit 67a3fe8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
12 changes: 6 additions & 6 deletions lambdas/handlers/manage_nrl_pointer_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 24 additions & 21 deletions lambdas/services/nrl_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = {
Expand All @@ -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())
Expand All @@ -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:
Expand Down

0 comments on commit 67a3fe8

Please sign in to comment.