fix(_logging.py): add loglevel and timestamp to json logs

Fixes https://github.com/BerriAI/litellm/issues/4248
This commit is contained in:
Krrish Dholakia 2024-06-17 18:57:20 -07:00
parent 4f32bca8d9
commit 4cddd1eb31
3 changed files with 18 additions and 7 deletions

View file

@ -1,7 +1,8 @@
import json
import logging
from logging import Formatter
import os
from logging import Formatter
from litellm import json_logs
# Set default log level to INFO
@ -14,8 +15,11 @@ class JsonFormatter(Formatter):
super(JsonFormatter, self).__init__()
def format(self, record):
json_record = {}
json_record["message"] = record.getMessage()
json_record = {
"message": record.getMessage(),
"level": record.levelname,
"timestamp": self.formatTime(record, self.datefmt),
}
return json.dumps(json_record)