From 55e9edef9d256b0046ba19d9a987fef269d012db Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Thu, 16 Jan 2025 14:29:03 -0500 Subject: [PATCH] update formatting --- tests/profiling_v2/gunicorn.conf.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/profiling_v2/gunicorn.conf.py b/tests/profiling_v2/gunicorn.conf.py index 6c7dc0729e..0ce8138be4 100644 --- a/tests/profiling_v2/gunicorn.conf.py +++ b/tests/profiling_v2/gunicorn.conf.py @@ -1,4 +1,5 @@ import logging +from datetime import datetime, timezone def post_fork(server, worker): @@ -10,11 +11,29 @@ def post_worker_init(worker): logging.info("Worker %s initialized", worker.pid) +class CustomFormatter(logging.Formatter): + """Custom formatter to include timezone offset in the log message.""" + + def formatTime(self, record, datefmt=None): + dt = datetime.fromtimestamp(record.created, tz=timezone.utc).astimezone() + milliseconds = int(record.msecs) + offset = dt.strftime("%z") # Get timezone offset in the form +0530 + if datefmt: + formatted_time = dt.strftime(datefmt) + else: + formatted_time = dt.strftime("%Y-%m-%d %H:%M:%S") + + # Add milliseconds and timezone offset + offset = dt.strftime("%z") # Timezone offset in the form +0530 + return f"{formatted_time}.{milliseconds:03d} {offset}" + + logconfig_dict = { "version": 1, "formatters": { "default": { - "format": "[%(asctime)s.%(msecs)03d +0000] [%(process)d] [%(levelname)s] %(message)s", + "()": CustomFormatter, # Use the custom formatter + "format": "[%(asctime)s] [%(process)d] [%(levelname)s] %(message)s", "datefmt": "%Y-%m-%d %H:%M:%S", }, },