From bb8db53e478b2fec8c456a605ccf123846c7bbe9 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Sat, 24 Jan 2026 10:21:31 -0800 Subject: [PATCH] remove changes to dependency files --- litellm/_logging.py | 60 ++++++++++++++++++++++++++++++++++++++ litellm/proxy/proxy_cli.py | 5 ++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/litellm/_logging.py b/litellm/_logging.py index b3156b15ba7..e222627e76c 100644 --- a/litellm/_logging.py +++ b/litellm/_logging.py @@ -166,6 +166,66 @@ def _initialize_loggers_with_handler(handler: logging.Handler): lg.propagate = False # prevent bubbling to parent/root +def _get_uvicorn_json_log_config(): + """ + Generate a uvicorn log_config dictionary that applies JSON formatting to all loggers. + + This ensures that uvicorn's access logs, error logs, and all application logs + are formatted as JSON when json_logs is enabled. + """ + json_formatter_class = "litellm._logging.JsonFormatter" + + # Use the module-level log_level variable for consistency + uvicorn_log_level = log_level.upper() + + log_config = { + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "json": { + "()": json_formatter_class, + }, + "default": { + "()": json_formatter_class, + }, + "access": { + "()": json_formatter_class, + }, + }, + "handlers": { + "default": { + "formatter": "json", + "class": "logging.StreamHandler", + "stream": "ext://sys.stdout", + }, + "access": { + "formatter": "access", + "class": "logging.StreamHandler", + "stream": "ext://sys.stdout", + }, + }, + "loggers": { + "uvicorn": { + "handlers": ["default"], + "level": uvicorn_log_level, + "propagate": False, + }, + "uvicorn.error": { + "handlers": ["default"], + "level": uvicorn_log_level, + "propagate": False, + }, + "uvicorn.access": { + "handlers": ["access"], + "level": uvicorn_log_level, + "propagate": False, + }, + }, + } + + return log_config + + def _turn_on_json(): """ Turn on JSON logging diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index 2059246674b..2bc1c8f8e98 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -127,6 +127,7 @@ class ProxyInitializationHelpers: Get the arguments for `uvicorn` worker """ import litellm + from litellm._logging import _get_uvicorn_json_log_config uvicorn_args = { "app": "litellm.proxy.proxy_server:app", @@ -137,8 +138,8 @@ class ProxyInitializationHelpers: print(f"Using log_config: {log_config}") # noqa uvicorn_args["log_config"] = log_config elif litellm.json_logs: - print("Using json logs. Setting log_config to None.") # noqa - uvicorn_args["log_config"] = None + # Use JSON log config for uvicorn to ensure all logs (including exceptions) are JSON + uvicorn_args["log_config"] = _get_uvicorn_json_log_config() if keepalive_timeout is not None: uvicorn_args["timeout_keep_alive"] = keepalive_timeout return uvicorn_args