Skip to content

Commit e6466c8

Browse files
logger: set LiteLLM loggers to WARNING by default; enable DEBUG with DEBUG_LLM confirmation (#23)
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 1f0f611 commit e6466c8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

openhands/core/logger.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@
3333
ENV_AUTO_CONFIG = os.getenv("LOG_AUTO_CONFIG", "true").lower() in {"1", "true", "yes"}
3434
ENV_DEBUG_LLM = os.getenv("DEBUG_LLM", "False").lower() in ["true", "1", "yes"]
3535

36+
37+
def _configure_litellm_logger(level: int) -> None:
38+
"""Force LiteLLM library loggers to a specific level regardless of root level."""
39+
for name in ("LiteLLM", "litellm"):
40+
logging.getLogger(name).setLevel(level)
41+
42+
3643
# Configure litellm logging based on DEBUG_LLM
44+
_ENABLE_LITELLM_DEBUG = False
3745
if ENV_DEBUG_LLM:
3846
confirmation = input(
3947
"\n⚠️ WARNING: You are enabling DEBUG_LLM which may expose sensitive information like API keys.\n"
4048
"This should NEVER be enabled in production.\n"
4149
"Type 'y' to confirm you understand the risks: "
4250
)
4351
if confirmation.lower() == "y":
52+
_ENABLE_LITELLM_DEBUG = True
4453
litellm.suppress_debug_info = False
4554
litellm.set_verbose = True # type: ignore
4655
else:
@@ -51,6 +60,9 @@
5160
litellm.suppress_debug_info = True
5261
litellm.set_verbose = False # type: ignore
5362

63+
# By default, suppress LiteLLM INFO/DEBUG logs regardless of root logger level
64+
_configure_litellm_logger(logging.DEBUG if _ENABLE_LITELLM_DEBUG else logging.WARNING)
65+
5466

5567
# ========= SETUP =========
5668
def setup_logging(

0 commit comments

Comments
 (0)