Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion litellm/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,34 @@ def _suppress_loggers():
]


def _get_loggers_to_initialize():
"""
Get all loggers that should be initialized with the JSON handler.

Includes third-party integration loggers (like langfuse) if they are
configured as callbacks.
"""
import litellm

loggers = list(ALL_LOGGERS)

# Add langfuse logger if langfuse is being used as a callback
langfuse_callbacks = {"langfuse", "langfuse_otel"}
all_callbacks = set(litellm.success_callback + litellm.failure_callback)
if langfuse_callbacks & all_callbacks:
loggers.append(logging.getLogger("langfuse"))

return loggers


def _initialize_loggers_with_handler(handler: logging.Handler):
"""
Initialize all loggers with a handler

- Adds a handler to each logger
- Prevents bubbling to parent/root (critical to prevent duplicate JSON logs)
"""
for lg in ALL_LOGGERS:
for lg in _get_loggers_to_initialize():
lg.handlers.clear() # remove any existing handlers
lg.addHandler(handler) # add JSON formatter handler
lg.propagate = False # prevent bubbling to parent/root
Expand Down
Loading