Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

dekkers
Copy link
Contributor

@dekkers dekkers commented Oct 29, 2024

Changes

Add env variable for logging level. Work in progress, created PR so containers are build.

Issue link

You have to create an issue to link to this PR. If this really is not possible, write a very detailed description here and add this PR to the project board directly.

Please add the link to the issue after "Closes".

Closes ...

Demo

Please add some proof in the form of screenshots or screen recordings to show (off) new functionality, if there are interesting new features for end-users.

QA notes

Please add some information for QA on how to test the newly created code.


Code Checklist

  • All the commits in this PR are properly PGP-signed and verified.
  • This PR only contains functionality relevant to the issue.
  • I have written unit tests for the changes or fixes I made.
  • I have checked the documentation and made changes where necessary.
  • I have performed a self-review of my code and refactored it to the best of my abilities.
  • Tickets have been created for newly discovered issues.
  • For any non-trivial functionality, I have added integration and/or end-to-end tests.
  • I have informed others of any required .env changes files if required and changed the .env-dist accordingly.
  • I have included comments in the code to elaborate on what is not self-evident from the code itself, including references to issues and discussions online, or implicit behavior of an interface.

Checklist for code reviewers:

Copy-paste the checklist from the docs/source/templates folder into your comment.


Checklist for QA:

Copy-paste the checklist from the docs/source/templates folder into your comment.

@dekkers dekkers changed the title Add env var for log level Add env var for logging level Oct 29, 2024
Copy link

key.split("BOEFJE_", 1)[1]: value
for key, value in os.environ.items()
if key.startswith("BOEFJE_") and key in allowed_keys
key[7:]: value for key, value in os.environ.items() if key.startswith("BOEFJE_") and key[7:] not in allowed_keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_env = {key.removeprefix("BOEFJE_"): value for key, value in os.environ.items() if key.startswith("BOEFJE_") and key.removeprefix("BOEFJE_") not in allowed_keys}

@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log_level: str = Field("INFO", description="Logging level")
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = Field("INFO", description="Logging level")

Comment on lines +45 to +51
# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants