fix(_logging.py): fix timestamp format for json logs

Outputs timestamp in ISO 8601 format to work with fluentbit
This commit is contained in:
Krrish Dholakia 2024-06-20 15:20:21 -07:00
parent 248ee488f0
commit 14da2d5ade
2 changed files with 9 additions and 1 deletions

View file

@ -2,6 +2,7 @@ import json
import logging
import os
import traceback
from datetime import datetime
from logging import Formatter
set_verbose = False
@ -22,11 +23,16 @@ class JsonFormatter(Formatter):
def __init__(self):
super(JsonFormatter, self).__init__()
def formatTime(self, record, datefmt=None):
# Use datetime to format the timestamp in ISO 8601 format
dt = datetime.fromtimestamp(record.created)
return dt.isoformat()
def format(self, record):
json_record = {
"message": record.getMessage(),
"level": record.levelname,
"timestamp": self.formatTime(record, self.datefmt),
"timestamp": self.formatTime(record),
}
return json.dumps(json_record)

View file

@ -1,3 +1,5 @@
### DEPRECATED ###
## unused file. initially written for json logging on proxy.
import json
import logging
import os