From: saul.gill Date: Fri, 7 Feb 2025 11:05:38 +0000 (+0000) Subject: Add timestamp to request/response logs X-Git-Tag: 2.8.1^0 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=7c905365b4532d39c34d6c8f0073c4d67d3d8d38;p=sim%2Fa1-interface.git Add timestamp to request/response logs Issue-ID: NONRTRIC-753 Change-Id: I029283b72d7479c495123230f83075c884984cf3 Signed-off-by: saul.gill --- 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)