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 logging
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
from datetime import datetime
|
||||||
from logging import Formatter
|
from logging import Formatter
|
||||||
|
|
||||||
set_verbose = False
|
set_verbose = False
|
||||||
|
@ -22,11 +23,16 @@ class JsonFormatter(Formatter):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(JsonFormatter, self).__init__()
|
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):
|
def format(self, record):
|
||||||
json_record = {
|
json_record = {
|
||||||
"message": record.getMessage(),
|
"message": record.getMessage(),
|
||||||
"level": record.levelname,
|
"level": record.levelname,
|
||||||
"timestamp": self.formatTime(record, self.datefmt),
|
"timestamp": self.formatTime(record),
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.dumps(json_record)
|
return json.dumps(json_record)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
### DEPRECATED ###
|
||||||
|
## unused file. initially written for json logging on proxy.
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue