Skip to content

Commit

Permalink
fix(proxy_cli.py): enable json logging via litellm_settings param on …
Browse files Browse the repository at this point in the history
…config

allows user to enable json logs without needing to figure out env variables
  • Loading branch information
krrishdholakia committed May 30, 2024
1 parent 793c7b1 commit 3167bee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion litellm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import threading, requests, os
from typing import Callable, List, Optional, Dict, Union, Any, Literal
from litellm.caching import Cache
from litellm._logging import set_verbose, _turn_on_debug, verbose_logger, json_logs
from litellm._logging import (
set_verbose,
_turn_on_debug,
verbose_logger,
json_logs,
_turn_on_json,
)
from litellm.proxy._types import (
KeyManagementSystem,
KeyManagementSettings,
Expand Down
10 changes: 10 additions & 0 deletions litellm/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def format(self, record):
verbose_logger.addHandler(handler)


def _turn_on_json():
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
handler.setFormatter(JsonFormatter())

verbose_router_logger.addHandler(handler)
verbose_proxy_logger.addHandler(handler)
verbose_logger.addHandler(handler)


def _turn_on_debug():
verbose_logger.setLevel(level=logging.DEBUG) # set package log to debug
verbose_router_logger.setLevel(level=logging.DEBUG) # set router logs to debug
Expand Down
13 changes: 13 additions & 0 deletions litellm/proxy/proxy_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,19 @@ def _make_openai_completion():

proxy_config = ProxyConfig()
_config = asyncio.run(proxy_config.get_config(config_file_path=config))
### LITELLM SETTINGS ###
litellm_settings = _config.get("litellm_settings", None)
if (
litellm_settings is not None
and "json_logs" in litellm_settings
and litellm_settings["json_logs"] == True
):
import litellm

litellm.json_logs = True

litellm._turn_on_json()
### GENERAL SETTINGS ###
general_settings = _config.get("general_settings", {})
if general_settings is None:
general_settings = {}
Expand Down

0 comments on commit 3167bee

Please sign in to comment.