Skip to content

Commit

Permalink
Add env var for log level
Browse files Browse the repository at this point in the history
  • Loading branch information
dekkers committed Oct 29, 2024
1 parent 3c4b5c0 commit ba4386d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions mula/scheduler/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions mula/scheduler/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ba4386d

Please sign in to comment.