Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit noisy logs & keep the root logger info #768

Merged
merged 2 commits into from
Sep 17, 2024
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
17 changes: 15 additions & 2 deletions livekit-agents/livekit/agents/cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@

from ..plugin import Plugin

# noisy loggers are set to warn by default
NOISY_LOGGERS = [
"httpx",
"httpcore",
"openai",
"livekit",
"watchfiles",
]

# skip default LogRecord attributes
# http://docs.python.org/library/logging.html#logrecord-attributes
_RESERVED_ATTRS: Tuple[str, ...] = (
Expand Down Expand Up @@ -92,6 +101,7 @@ def format(self, record: logging.LogRecord) -> str:
"""Formats a log record and serializes to json"""
message_dict: Dict[str, Any] = {}
message_dict["level"] = record.levelname
message_dict["name"] = record.name

if isinstance(record.msg, dict):
message_dict = record.msg
Expand Down Expand Up @@ -196,9 +206,12 @@ def setup_logging(log_level: str, devmode: bool) -> None:

root = logging.getLogger()
root.addHandler(handler)
root.setLevel(log_level)

if root.level == logging.NOTSET:
root.setLevel(logging.WARN)
for noisy_logger in NOISY_LOGGERS:
logger = logging.getLogger(noisy_logger)
if logger.level == logging.NOTSET:
logger.setLevel(logging.WARN)

from ..log import logger

Expand Down
Loading