forked from phoenix/litellm-mirror
fix(_logging.py): fix timestamp format for json logs
Outputs timestamp in ISO 8601 format to work with fluentbit
This commit is contained in:
parent
248ee488f0
commit
14da2d5ade
2 changed files with 9 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
### DEPRECATED ###
|
||||
## unused file. initially written for json logging on proxy.
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue