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:
+30
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user