Skip to content

Commit

Permalink
Verify log_level
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Jan 15, 2025
1 parent dcc18a4 commit fa3bdc3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dnstapir/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import structlog
from structlog.types import EventDict, Processor

VALID_LOG_LEVELS = set(["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"])


def drop_color_message_key(_, __, event_dict: EventDict) -> EventDict:
"""
Expand All @@ -18,6 +20,11 @@ def drop_color_message_key(_, __, event_dict: EventDict) -> EventDict:


def setup_logging(json_logs: bool = False, log_level: str = "INFO") -> None:
"""Set up logging"""

if log_level.upper() not in VALID_LOG_LEVELS:
raise ValueError(f"Invalid log level: {log_level}")

timestamper = structlog.processors.TimeStamper(fmt="iso")

shared_processors: list[Processor] = [
Expand Down

0 comments on commit fa3bdc3

Please sign in to comment.