Skip to content

Commit

Permalink
update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taegyunkim committed Jan 16, 2025
1 parent 7bcb457 commit 55e9ede
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/profiling_v2/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from datetime import datetime, timezone


def post_fork(server, worker):
Expand All @@ -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",
},
},
Expand Down

0 comments on commit 55e9ede

Please sign in to comment.