SPB Git

spb/findata

Public
1.2 KB · 34 lines python
1from __future__ import annotations23import logging4import sys56import structlog78from findata_core.config import get_settings9from findata_core.redact import RedactingFilter101112def configure_logging(level: str = "INFO") -> None:13    settings = get_settings()14    logging.basicConfig(level=level, stream=sys.stdout, format="%(message)s")15    # Never let httpx/httpcore print request URLs (they contain the vendor user id).16    for noisy in ("httpx", "httpcore", "urllib3"):17        logging.getLogger(noisy).setLevel(logging.WARNING)18    structlog.configure(19        processors=[20            structlog.contextvars.merge_contextvars,21            structlog.processors.add_log_level,22            structlog.processors.TimeStamper(fmt="iso", utc=True),23            RedactingFilter(settings.secret_values()),24            structlog.processors.JSONRenderer() if settings.is_production else structlog.dev.ConsoleRenderer(),25        ],26        wrapper_class=structlog.make_filtering_bound_logger(logging.getLevelName(level)),27        logger_factory=structlog.PrintLoggerFactory(),28        cache_logger_on_first_use=False,29    )303132def get_logger(name: str):  # type: ignore[no-untyped-def]33    return structlog.get_logger(name)34
Files · de3e9e393936b8d9c1340b2c85d7ccb9ffa8264a
Menu

Theme