Add timestamp to request/response logs 43/14143/1 2.8.1
authorsaul.gill <saul.gill@est.tech>
Fri, 7 Feb 2025 11:05:38 +0000 (11:05 +0000)
committersaul.gill <saul.gill@est.tech>
Fri, 7 Feb 2025 11:20:25 +0000 (11:20 +0000)
Issue-ID: NONRTRIC-753
Change-Id: I029283b72d7479c495123230f83075c884984cf3
Signed-off-by: saul.gill <saul.gill@est.tech>
near-rt-ric-simulator/src/common/payload_logging.py

index 3316511..68d8124 100644 (file)
@@ -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)