From ba4386d63d1ea7904f6331f7dbb89c2eb2e4459d Mon Sep 17 00:00:00 2001 From: Jeroen Dekkers Date: Tue, 29 Oct 2024 11:57:09 +0100 Subject: [PATCH] Add env var for log level --- mula/scheduler/config/settings.py | 1 + mula/scheduler/context/context.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/mula/scheduler/config/settings.py b/mula/scheduler/config/settings.py index f095350b8bb..912e6774e23 100644 --- a/mula/scheduler/config/settings.py +++ b/mula/scheduler/config/settings.py @@ -48,6 +48,7 @@ class Settings(BaseSettings): debug: bool = Field(False, alias="DEBUG", description="Enables/disables global debugging mode") log_cfg: Path = Field(BASE_DIR / "logging.json", description="Path to the logging configuration file") + log_level: str = Field("INFO", description="Logging level") collect_metrics: bool = Field( False, description="Enables/disables the collection of metrics to be used with tools like Prometheus" diff --git a/mula/scheduler/context/context.py b/mula/scheduler/context/context.py index 6fb5ea80105..b7c4aed84ea 100644 --- a/mula/scheduler/context/context.py +++ b/mula/scheduler/context/context.py @@ -42,6 +42,12 @@ def __init__(self) -> None: with Path(self.config.log_cfg).open("rt", encoding="utf-8") as f: logging.config.dictConfig(json.load(f)) + # Set the logging level to the value specified by the env var + level = logging.getLevelName(self.config.log_level.upper()) + root_logger = logging.getLogger() + root_logger.setLevel(level) + root_logger.handlers[0].setLevel(level) + # Check if we enabled structured logging in the configuration if self.config.logging_format == "json": structlog.configure(