Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

[Fix] Initialize customLogger in failure handlers to ensure callbacks fire

Yuneng Jiang86dd36e12a5b
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py
index 53478dcbb65..7395b65626f 100644
--- a/litellm/litellm_core_utils/litellm_logging.py
+++ b/litellm/litellm_core_utils/litellm_logging.py
@@ -3000,9 +3000,10 @@ class Logging(LiteLLMLoggingBaseClass):
litellm_call_id=self.model_call_details["litellm_call_id"],
print_verbose=print_verbose,
)
- if (
- callable(callback) and customLogger is not None
- ): # custom logger functions
+ if callable(callback): # custom logger functions
+ global customLogger
+ if customLogger is None:
+ customLogger = CustomLogger()
customLogger.log_event(
kwargs=self.model_call_details,
response_obj=result,
@@ -3143,9 +3144,10 @@ class Logging(LiteLLMLoggingBaseClass):
start_time=start_time,
end_time=end_time,
) # type: ignore
- if (
- callable(callback) and customLogger is not None
- ): # custom logger functions
+ if callable(callback): # custom logger functions
+ global customLogger
+ if customLogger is None:
+ customLogger = CustomLogger()
await customLogger.async_log_event(
kwargs=self.model_call_details,
response_obj=result,