From 86dd36e12a5bbe646c1333cfa7b1f4dce8276fee Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Mon, 30 Mar 2026 19:18:30 -0700 Subject: [PATCH] [Fix] Initialize customLogger in failure handlers to ensure callbacks fire The sync and async failure handlers guarded plain-function callbacks with `customLogger is not None`, but customLogger was only initialized in the success handler path. If a request failed without any prior success in the process, the failure callback was silently skipped. Co-Authored-By: Claude Opus 4.6 (1M context) --- litellm/litellm_core_utils/litellm_logging.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 53478dcbb6..7395b65626 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,