Skip to content

Commit

Permalink
Allow the setting of log level by env vars
Browse files Browse the repository at this point in the history
Required by #637
  • Loading branch information
adamdougal committed Apr 9, 2024
1 parent 9247f62 commit c6e0cb7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions code/backend/batch/utilities/helpers/EnvHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def __init__(self, **kwargs) -> None:
# Wrapper for Azure Key Vault
self.secretHelper = SecretHelper()

self.LOGLEVEL = os.environ.get("LOGLEVEL", "INFO").upper()

# Azure Search
self.AZURE_SEARCH_SERVICE = os.getenv("AZURE_SEARCH_SERVICE", "")
self.AZURE_SEARCH_INDEX = os.getenv("AZURE_SEARCH_INDEX", "")
Expand Down
2 changes: 2 additions & 0 deletions code/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ def create_app():
app = Flask(__name__)
env_helper: EnvHelper = EnvHelper()

logging.basicConfig(level=env_helper.LOGLEVEL)

@app.route("/", defaults={"path": "index.html"})
@app.route("/<path:path>")
def static_file(path):
Expand Down
19 changes: 19 additions & 0 deletions code/tests/utilities/test_EnvHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ def test_app_insights_enabled(monkeypatch: MonkeyPatch, value, expected):

# then
assert actual_appinsights_enabled == expected


def test_sets_default_log_level_when_unset():
# when
env_helper = EnvHelper()

# then
assert env_helper.LOGLEVEL == "INFO"


def test_uses_and_uppercases_log_level_when_set(monkeypatch: MonkeyPatch):
# given
monkeypatch.setenv("LOGLEVEL", "deBug")

# when
env_helper = EnvHelper()

# then
assert env_helper.LOGLEVEL == "DEBUG"

0 comments on commit c6e0cb7

Please sign in to comment.