Skip to content

Commit

Permalink
Log configuration (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza authored Sep 8, 2024
1 parent 02c2707 commit 0aa40e9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ldp/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import logging.config

import litellm


def configure_log_levels() -> None:
"""Configure log levels."""
# Set sane default LiteLLM logging configuration
# SEE: https://docs.litellm.ai/docs/observability/telemetry
litellm.telemetry = False

logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": False,
# Lower level for httpx and LiteLLM
"loggers": {
"httpx": {"level": "WARNING"},
# SEE: https://github.com/BerriAI/litellm/issues/2256
"LiteLLM": {"level": "WARNING"},
},
})


def configure_stdout_logs(
stdout_level: int | str = logging.INFO,
fmt: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
) -> None:
"""Configure root logger to log to stdout.
Args:
stdout_level: Log level to be emitted to stdout.
fmt: Optional format string.
"""
logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": False,
"formatters": {"standard": {"format": fmt}},
"handlers": {
"stdout": {
"level": "INFO",
"formatter": "standard",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
},
},
"root": {"level": stdout_level, "handlers": ["stdout"]},
})
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import torch
from aviary.env import DummyEnv

from ldp.utils import configure_log_levels

IN_GITHUB_ACTIONS: bool = os.getenv("GITHUB_ACTIONS") == "true"


Expand All @@ -14,6 +16,11 @@ def fixture_dummy_env() -> DummyEnv:
return DummyEnv()


@pytest.fixture(scope="session", autouse=True)
def _fixture_set_up_environment() -> None:
configure_log_levels()


def set_seed(seed: int | None) -> None:
if seed is None:
return
Expand Down

0 comments on commit 0aa40e9

Please sign in to comment.