use safe init_verbose_loggers

This commit is contained in:
Ishaan Jaff 2024-08-05 20:56:48 -07:00
parent 818a70838d
commit d91b1c93d1

View file

@ -136,66 +136,81 @@ async def get_otel_spans():
# Helper functions for debugging # Helper functions for debugging
def init_verbose_loggers(): def init_verbose_loggers():
worker_config = litellm.get_secret("WORKER_CONFIG") try:
if os.path.isfile(worker_config): worker_config = litellm.get_secret("WORKER_CONFIG")
return if os.path.isfile(worker_config):
# if not, assume it's a json string return
_settings = json.loads(os.getenv("WORKER_CONFIG")) # if not, assume it's a json string
if not isinstance(_settings, dict): _settings = json.loads(os.getenv("WORKER_CONFIG"))
return if not isinstance(_settings, dict):
return
debug = _settings.get("debug", None) debug = _settings.get("debug", None)
detailed_debug = _settings.get("detailed_debug", None) detailed_debug = _settings.get("detailed_debug", None)
if debug is True: # this needs to be first, so users can see Router init debugg if debug is True: # this needs to be first, so users can see Router init debugg
import logging import logging
from litellm._logging import ( from litellm._logging import (
verbose_logger, verbose_logger,
verbose_proxy_logger, verbose_proxy_logger,
verbose_router_logger, verbose_router_logger,
) )
# this must ALWAYS remain logging.INFO, DO NOT MODIFY THIS # this must ALWAYS remain logging.INFO, DO NOT MODIFY THIS
verbose_logger.setLevel(level=logging.INFO) # sets package logs to info verbose_logger.setLevel(level=logging.INFO) # sets package logs to info
verbose_router_logger.setLevel(level=logging.INFO) # set router logs to info verbose_router_logger.setLevel(
verbose_proxy_logger.setLevel(level=logging.INFO) # set proxy logs to info level=logging.INFO
if detailed_debug == True: ) # set router logs to info
import logging verbose_proxy_logger.setLevel(level=logging.INFO) # set proxy logs to info
if detailed_debug == True:
import logging
from litellm._logging import ( from litellm._logging import (
verbose_logger, verbose_logger,
verbose_proxy_logger, verbose_proxy_logger,
verbose_router_logger, verbose_router_logger,
) )
verbose_logger.setLevel(level=logging.DEBUG) # set package log to debug verbose_logger.setLevel(level=logging.DEBUG) # set package log to debug
verbose_router_logger.setLevel(level=logging.DEBUG) # set router logs to debug verbose_router_logger.setLevel(
verbose_proxy_logger.setLevel(level=logging.DEBUG) # set proxy logs to debug level=logging.DEBUG
elif debug == False and detailed_debug == False: ) # set router logs to debug
# users can control proxy debugging using env variable = 'LITELLM_LOG' verbose_proxy_logger.setLevel(
litellm_log_setting = os.environ.get("LITELLM_LOG", "") level=logging.DEBUG
if litellm_log_setting != None: ) # set proxy logs to debug
if litellm_log_setting.upper() == "INFO": elif debug == False and detailed_debug == False:
import logging # users can control proxy debugging using env variable = 'LITELLM_LOG'
litellm_log_setting = os.environ.get("LITELLM_LOG", "")
if litellm_log_setting != None:
if litellm_log_setting.upper() == "INFO":
import logging
from litellm._logging import verbose_proxy_logger, verbose_router_logger from litellm._logging import (
verbose_proxy_logger,
verbose_router_logger,
)
# this must ALWAYS remain logging.INFO, DO NOT MODIFY THIS # this must ALWAYS remain logging.INFO, DO NOT MODIFY THIS
verbose_router_logger.setLevel( verbose_router_logger.setLevel(
level=logging.INFO level=logging.INFO
) # set router logs to info ) # set router logs to info
verbose_proxy_logger.setLevel( verbose_proxy_logger.setLevel(
level=logging.INFO level=logging.INFO
) # set proxy logs to info ) # set proxy logs to info
elif litellm_log_setting.upper() == "DEBUG": elif litellm_log_setting.upper() == "DEBUG":
import logging import logging
from litellm._logging import verbose_proxy_logger, verbose_router_logger from litellm._logging import (
verbose_proxy_logger,
verbose_router_logger,
)
verbose_router_logger.setLevel( verbose_router_logger.setLevel(
level=logging.DEBUG level=logging.DEBUG
) # set router logs to info ) # set router logs to info
verbose_proxy_logger.setLevel( verbose_proxy_logger.setLevel(
level=logging.DEBUG level=logging.DEBUG
) # set proxy logs to debug ) # set proxy logs to debug
except Exception as e:
verbose_logger.warning(f"Failed to init verbose loggers: {str(e)}")