Merge pull request #146 from SDSRV-IDP/dev/logging

Consilidate logger
This commit is contained in:
Phan Thành Trung 2024-06-26 16:43:40 +07:00 committed by GitHub Enterprise
commit 8e23c2e836
3 changed files with 9 additions and 4 deletions

View File

@ -229,6 +229,7 @@ class CtelViewSet(viewsets.ViewSet):
"invoice": invoice_file_objs "invoice": invoice_file_objs
} }
rq_id = provider_code + "_" + datetime.now().strftime("%Y%m%d%H%M%S") + "_" + uuid.uuid4().hex rq_id = provider_code + "_" + datetime.now().strftime("%Y%m%d%H%M%S") + "_" + uuid.uuid4().hex
logger.info(f"Creating a request: {rq_id}")
is_test_request = validated_data.get("is_test_request", False) is_test_request = validated_data.get("is_test_request", False)
count = 0 count = 0
doc_files_with_type = [] doc_files_with_type = []

View File

@ -7,10 +7,10 @@ class VerboseTask(Task):
def on_failure(self, exc, task_id, args, kwargs, einfo): def on_failure(self, exc, task_id, args, kwargs, einfo):
# Task failed. What do you want to do? # Task failed. What do you want to do?
logger.error('FAILURE: Task raised an exception: {}'.format(exc)) logger.error(f'FAILURE: Task: {self.name} - {task_id} | Task raised an exception: {exc}')
def on_success(self, retval, task_id, args, kwargs): def on_success(self, retval, task_id, args, kwargs):
logger.info(f"SUCCESS: Task: {task_id} succeeded | retval: {retval} | args: {args} | kwargs: {kwargs}") logger.info(f"SUCCESS: Task: {self.name} - {task_id} | retval: {retval} | args: {args} | kwargs: {kwargs}")
def before_start(self, task_id, args, kwargs): def before_start(self, task_id, args, kwargs):
logger.info(f"BEFORE_START: Task: {task_id} | args: {args} | kwargs: {kwargs}") logger.info(f"BEFORE_START: Task: {self.name} - {task_id} | args: {args} | kwargs: {kwargs}")

View File

@ -20,7 +20,11 @@ class LoggingMiddleware(MiddlewareMixin):
def process_response(self, request, response): def process_response(self, request, response):
trace_id = request.META.get('X-Trace-ID', str(uuid.uuid4())) trace_id = request.META.get('X-Trace-ID', str(uuid.uuid4()))
response_body = response.content.decode("utf-8") if response.content else "" try:
response_body = response.content.decode("utf-8") if response.content else ""
except Exception as e:
logger.error(e)
response_body = ""
logger.info(f"Response: {request.method} {request.path} | Trace ID: {trace_id} | " logger.info(f"Response: {request.method} {request.path} | Trace ID: {trace_id} | "
f"Status: {response.status_code} | Body: {response_body}") f"Status: {response.status_code} | Body: {response_body}")