This commit is contained in:
vasilije 2025-08-27 15:51:45 +02:00
parent c933290886
commit 9df34662cc

View file

@ -18,40 +18,40 @@ def configure_external_library_logging():
# Set environment variables to suppress LiteLLM logging
os.environ.setdefault("LITELLM_LOG", "ERROR")
os.environ.setdefault("LITELLM_SET_VERBOSE", "False")
# Configure LiteLLM logging to reduce verbosity
try:
import litellm
# Disable verbose logging
litellm.set_verbose = False
# Set additional LiteLLM configuration
if hasattr(litellm, 'suppress_debug_info'):
if hasattr(litellm, "suppress_debug_info"):
litellm.suppress_debug_info = True
if hasattr(litellm, 'turn_off_message'):
if hasattr(litellm, "turn_off_message"):
litellm.turn_off_message = True
if hasattr(litellm, '_turn_on_debug'):
if hasattr(litellm, "_turn_on_debug"):
litellm._turn_on_debug = False
# Comprehensive logger suppression
loggers_to_suppress = [
"litellm",
"litellm.litellm_core_utils.logging_worker",
"litellm.litellm_core_utils",
"litellm.litellm_core_utils",
"litellm.proxy",
"litellm.router",
"openai._base_client",
"LiteLLM", # Capital case variant
"LiteLLM.core",
"LiteLLM.logging_worker",
"litellm.logging_worker"
"litellm.logging_worker",
]
for logger_name in loggers_to_suppress:
logging.getLogger(logger_name).setLevel(logging.CRITICAL)
logging.getLogger(logger_name).disabled = True
except ImportError:
# LiteLLM not available, skip configuration
pass
@ -272,63 +272,72 @@ def setup_logging(log_level=None, name=None):
# Configure external library logging early to suppress verbose output
configure_external_library_logging()
# Add custom filter to suppress LiteLLM worker cancellation errors
class LiteLLMCancellationFilter(logging.Filter):
"""Filter to suppress LiteLLM worker cancellation messages"""
def filter(self, record):
# Check if this is a LiteLLM-related logger
if hasattr(record, 'name') and 'litellm' in record.name.lower():
if hasattr(record, "name") and "litellm" in record.name.lower():
return False
# Check message content for cancellation errors
if hasattr(record, 'msg') and record.msg:
if hasattr(record, "msg") and record.msg:
msg_str = str(record.msg).lower()
if any(keyword in msg_str for keyword in [
'loggingworker cancelled',
'logging_worker.py',
'cancellederror',
'litellm:error'
]):
if any(
keyword in msg_str
for keyword in [
"loggingworker cancelled",
"logging_worker.py",
"cancellederror",
"litellm:error",
]
):
return False
# Check formatted message
try:
if hasattr(record, 'getMessage'):
if hasattr(record, "getMessage"):
formatted_msg = record.getMessage().lower()
if any(keyword in formatted_msg for keyword in [
'loggingworker cancelled',
'logging_worker.py',
'cancellederror',
'litellm:error'
]):
if any(
keyword in formatted_msg
for keyword in [
"loggingworker cancelled",
"logging_worker.py",
"cancellederror",
"litellm:error",
]
):
return False
except:
pass
return True
# Apply the filter to root logger and specific loggers
cancellation_filter = LiteLLMCancellationFilter()
logging.getLogger().addFilter(cancellation_filter)
logging.getLogger('litellm').addFilter(cancellation_filter)
logging.getLogger("litellm").addFilter(cancellation_filter)
# Add custom filter to suppress LiteLLM worker cancellation errors
class LiteLLMFilter(logging.Filter):
def filter(self, record):
# Suppress LiteLLM worker cancellation errors
if hasattr(record, 'msg') and isinstance(record.msg, str):
if hasattr(record, "msg") and isinstance(record.msg, str):
msg_lower = record.msg.lower()
if any(phrase in msg_lower for phrase in [
'loggingworker cancelled',
'cancellederror',
'logging_worker.py',
'loggingerror'
]):
if any(
phrase in msg_lower
for phrase in [
"loggingworker cancelled",
"cancellederror",
"logging_worker.py",
"loggingerror",
]
):
return False
return True
# Apply filter to root logger
litellm_filter = LiteLLMFilter()
logging.getLogger().addFilter(litellm_filter)