mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
feat(proxy_cli.py): support json logs on proxy
allow user to enable 'json logs' for proxy server
This commit is contained in:
parent
0016477d3b
commit
00d47f3d3b
4 changed files with 34 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
import logging, os
|
||||
|
||||
set_verbose = False
|
||||
json_logs = False
|
||||
json_logs = bool(os.getenv("JSON_LOGS", False))
|
||||
# Create a handler for the logger (you may need to adapt this based on your needs)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.DEBUG)
|
||||
|
|
20
litellm/proxy/_logging.py
Normal file
20
litellm/proxy/_logging.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import json
|
||||
import logging
|
||||
from logging import Formatter
|
||||
|
||||
|
||||
class JsonFormatter(Formatter):
|
||||
def __init__(self):
|
||||
super(JsonFormatter, self).__init__()
|
||||
|
||||
def format(self, record):
|
||||
json_record = {}
|
||||
json_record["message"] = record.getMessage()
|
||||
return json.dumps(json_record)
|
||||
|
||||
|
||||
logger = logging.root
|
||||
handler = logging.StreamHandler()
|
||||
handler.setFormatter(JsonFormatter())
|
||||
logger.handlers = [handler]
|
||||
logger.setLevel(logging.DEBUG)
|
|
@ -17,6 +17,7 @@ if litellm_mode == "DEV":
|
|||
from importlib import resources
|
||||
import shutil
|
||||
|
||||
|
||||
telemetry = None
|
||||
|
||||
|
||||
|
@ -505,6 +506,7 @@ def run_server(
|
|||
port = random.randint(1024, 49152)
|
||||
|
||||
from litellm.proxy.proxy_server import app
|
||||
import litellm
|
||||
|
||||
if run_gunicorn == False:
|
||||
if ssl_certfile_path is not None and ssl_keyfile_path is not None:
|
||||
|
@ -518,6 +520,14 @@ def run_server(
|
|||
ssl_keyfile=ssl_keyfile_path,
|
||||
ssl_certfile=ssl_certfile_path,
|
||||
) # run uvicorn
|
||||
else:
|
||||
print(f"litellm.json_logs: {litellm.json_logs}")
|
||||
if litellm.json_logs:
|
||||
from litellm.proxy._logging import logger
|
||||
|
||||
uvicorn.run(
|
||||
app, host=host, port=port, log_config=None
|
||||
) # run uvicorn w/ json
|
||||
else:
|
||||
uvicorn.run(app, host=host, port=port) # run uvicorn
|
||||
elif run_gunicorn == True:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue