From 7c905365b4532d39c34d6c8f0073c4d67d3d8d38 Mon Sep 17 00:00:00 2001 From: "saul.gill" Date: Fri, 7 Feb 2025 11:05:38 +0000 Subject: [PATCH] Add timestamp to request/response logs Issue-ID: NONRTRIC-753 Change-Id: I029283b72d7479c495123230f83075c884984cf3 Signed-off-by: saul.gill --- near-rt-ric-simulator/src/common/payload_logging.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/near-rt-ric-simulator/src/common/payload_logging.py b/near-rt-ric-simulator/src/common/payload_logging.py index 3316511..68d8124 100644 --- a/near-rt-ric-simulator/src/common/payload_logging.py +++ b/near-rt-ric-simulator/src/common/payload_logging.py @@ -17,6 +17,7 @@ from var_declaration import app from flask import Flask, request, Response +from datetime import datetime #Constants TEXT_PLAIN='text/plain' @@ -41,7 +42,8 @@ def set_payload_logging(state): @app.app.before_request def log_request_info(): if (payload_log is True): - print('') + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] # Format timestamp with milliseconds + print(f"\n[{timestamp}]") print('-----Request-----') print('Req Headers: ', request.headers) print('Req Body: ', request.get_data()) @@ -49,6 +51,8 @@ def log_request_info(): # Generic function to log http header and payload - called after the response @app.app.after_request def log_response_info(response): + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] # Format timestamp with milliseconds + print(f"\n[{timestamp}]") if (payload_log is True): print('-----Response-----') print('Resp Headers: ', response.headers) -- 2.16.6