feat(logging): honor the LOG_LEVEL environment variable

LOG_LEVEL was documented but never read; the level was fixed at INFO.
The JSON handler now sits on the "src" package logger so all service
modules share format and level. Invalid values fall back to INFO.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 18:32:58 +01:00
co-authored by Claude Fable 5.2
parent 7aa4506dd7
commit 4ff994a299
2 changed files with 62 additions and 8 deletions
+30 -1
View File
@@ -1,9 +1,10 @@
import base64
import logging
import pytest
from fastapi.testclient import TestClient
from src.main import app
from src.main import app, configure_logging
@pytest.fixture
@@ -93,3 +94,31 @@ def test_validate_pflichtfelder(client):
def test_validate_empty_checks(client):
response = client.post("/validate", json={"xml_data": {}, "checks": []})
assert response.status_code == 200
class TestLogLevel:
"""LOG_LEVEL environment variable controls the service log level."""
@pytest.fixture(autouse=True)
def _restore_level(self):
yield
logging.getLogger("src").setLevel(logging.INFO)
def test_log_level_from_env(self, monkeypatch):
monkeypatch.setenv("LOG_LEVEL", "debug")
configure_logging()
assert logging.getLogger("src").level == logging.DEBUG
assert logging.getLogger("src.extractor").getEffectiveLevel() == logging.DEBUG
def test_default_is_info(self, monkeypatch):
monkeypatch.delenv("LOG_LEVEL", raising=False)
configure_logging()
assert logging.getLogger("src").level == logging.INFO
def test_invalid_value_falls_back_to_info(self, monkeypatch):
monkeypatch.setenv("LOG_LEVEL", "chatty")
configure_logging()
assert logging.getLogger("src").level == logging.INFO