mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
get_custom_loggers_for_type
This commit is contained in:
parent
c3e33495b5
commit
98c5ffdb20
1 changed files with 15 additions and 8 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue