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]

get_custom_loggers_for_type

Ishaan Jaff730f61f476fc
diff --git a/litellm/litellm_core_utils/logging_callback_manager.py b/litellm/litellm_core_utils/logging_callback_manager.py
index a20e826c43e..c57a2401b7b 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)]