diff --git a/sotrplib/cli.py b/sotrplib/cli.py index 63335c1..a996925 100644 --- a/sotrplib/cli.py +++ b/sotrplib/cli.py @@ -2,11 +2,18 @@ Command-line interface for sotrplib. """ +import logging from argparse import ArgumentParser from pathlib import Path +import structlog + from sotrplib.config.config import Settings +structlog.configure( + wrapper_class=structlog.make_filtering_bound_logger(logging.INFO), +) + def parse_args() -> ArgumentParser: ap = ArgumentParser( diff --git a/sotrplib/config/config.py b/sotrplib/config/config.py index 35e8dc6..bd2ed5e 100644 --- a/sotrplib/config/config.py +++ b/sotrplib/config/config.py @@ -1,3 +1,4 @@ +import logging from pathlib import Path from typing import Any, Literal @@ -102,6 +103,8 @@ class Settings(BaseSettings): profile: bool = False "Enable pyinstrument profiling" + log_level: int | str = logging.INFO + # Read environment and command line settings to override default model_config = SettingsConfigDict(env_prefix="sotrp_", extra="ignore") @@ -112,6 +115,9 @@ def from_file(cls, config_path: Path | str) -> "Settings": return cls.model_validate_json(handle.read()) def to_dependencies(self) -> dict[str, Any]: + structlog.configure( + wrapper_class=structlog.make_filtering_bound_logger(self.log_level), + ) log = structlog.get_logger() contents = {