-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add env var for logging level #3751
base: main
Are you sure you want to change the base?
Changes from all commits
ba4386d
8e1881f
e084073
a199296
ee9582a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
collect_metrics: bool = Field( | ||||||
False, description="Enables/disables the collection of metrics to be used with tools like Prometheus" | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,14 @@ 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) | ||
logging.getLogger("uvicorn.access").setLevel(level) | ||
logging.getLogger("uvicorn.error").setLevel(level) | ||
Comment on lines
+45
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned offline and maybe for later: we could extend the dict config with this, so we'd have a consistent way of loading the logging configuration and printing out the logging configuration |
||
|
||
# Check if we enabled structured logging in the configuration | ||
if self.config.logging_format == "json": | ||
structlog.configure( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.