From 98c5ffdb20f59c2061e9a9780adf5c822cbf6a0e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 19 Mar 2025 16:36:41 -0700 Subject: [PATCH] get_custom_loggers_for_type --- .../logging_callback_manager.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/litellm/litellm_core_utils/logging_callback_manager.py b/litellm/litellm_core_utils/logging_callback_manager.py index a20e826c43..c57a2401b7 100644 --- a/litellm/litellm_core_utils/logging_callback_manager.py +++ b/litellm/litellm_core_utils/logging_callback_manager.py @@ -1,4 +1,4 @@ -from typing import Callable, List, Set, Union +from typing import Callable, List, Set, Type, Union import litellm from litellm._logging import verbose_logger @@ -86,21 +86,20 @@ class LoggingCallbackManager: callback=callback, parent_list=litellm._async_failure_callback ) - def remove_callback_from_list_by_object( - self, callback_list, obj - ): + def remove_callback_from_list_by_object(self, callback_list, obj): """ Remove callbacks that are methods of a particular object (e.g., router cleanup) """ - if not isinstance(callback_list, list): # Not list -> do nothing + if not isinstance(callback_list, list): # Not list -> do nothing return - - remove_list=[c for c in callback_list if hasattr(c, '__self__') and c.__self__ == obj] + + remove_list = [ + c for c in callback_list if hasattr(c, "__self__") and c.__self__ == obj + ] for c in remove_list: callback_list.remove(c) - def _add_string_callback_to_list( self, callback: str, parent_list: List[Union[CustomLogger, Callable, str]] ): @@ -254,3 +253,11 @@ class LoggingCallbackManager: ): matched_callbacks.add(callback) return matched_callbacks + + def get_custom_loggers_for_type( + self, callback_type: Type[CustomLogger] + ) -> List[CustomLogger]: + """ + Get all custom loggers that are instances of the given class type + """ + return [c for c in self._get_all_callbacks() if isinstance(c, callback_type)]