Skip to content

Commit 418effd

Browse files
committed
fix: clear logging handlers for LiteLLM to prevent duplicate logs
- Adds a function to clear existing logging handlers for LiteLLM components to ensure logs are not duplicated. - Updates the logging configuration to force basic logging handlers, preventing interference with Loguru.
1 parent b704a54 commit 418effd

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/llm_cli/logging/__init__.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
from ._fix_litellm import fix_litellm
12
from ._init import init
23
from ._loguru import init_loguru
34

4-
__all__ = ["init", "init_loguru"]
5+
__all__ = ["fix_litellm", "init", "init_loguru"]

src/llm_cli/logging/_fix_litellm.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import logging
2+
3+
import litellm # noqa: F401
4+
5+
6+
def fix_litellm() -> None:
7+
for name in ["LiteLLM Proxy", "LiteLLM Router", "LiteLLM"]:
8+
logging.getLogger(name).handlers.clear()

src/llm_cli/logging/_loguru.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ def emit(self, record: logging.LogRecord) -> None:
2929

3030

3131
def init_loguru() -> None:
32+
logging.basicConfig(handlers=[InterceptHandler()], level=0, force=True)
3233
logger.configure(handlers=[{"sink": sys.stderr, "level": "INFO"}])

0 commit comments

Comments
 (0)