diff --git a/.vscode/launch.json b/.vscode/launch.json index 8446e32f..00ed195b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,8 +6,8 @@ "type": "debugpy", "request": "launch", "module": "uvicorn", - "justMyCode": true, - "args": ["tad.main:app"], + "justMyCode": false, + "args": [ "--log-level", "warning" ,"tad.main:app"], "cwd": "${workspaceFolder}/", "env": { "PYTHONPATH": "${workspaceFolder}" diff --git a/sonar-project.properties b/sonar-project.properties index 1ee082ff..f13b4244 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -17,4 +17,4 @@ sonar.python.version=3.10,3.11,3.12 sonar.python.coverage.reportPaths=coverage.xml -sonar.coverage.exclusions=tad/migrations/ +sonar.coverage.exclusions=tad/migrations/* diff --git a/tad/core/log.py b/tad/core/log.py index b0a98a29..4850c419 100644 --- a/tad/core/log.py +++ b/tad/core/log.py @@ -30,7 +30,7 @@ }, }, "loggers": { - "tad": {"handlers": ["console", "file"], "level": "DEBUG", "propagate": True}, + "tad": {"handlers": ["console", "file"], "level": "DEBUG", "propagate": False}, }, } diff --git a/tests/core/test_log.py b/tests/core/test_log.py index 9cebc91a..4aae5629 100644 --- a/tests/core/test_log.py +++ b/tests/core/test_log.py @@ -6,8 +6,10 @@ from tad.core.log import configure_logging -def test_module_logging_setup(caplog: pytest.LogCaptureFixture): - configure_logging() +def test_logging_tad_module(caplog: pytest.LogCaptureFixture): + config = {"loggers": {"tad": {"propagate": True}}} + + configure_logging(config=config) logger = logging.getLogger("tad") @@ -22,7 +24,7 @@ def test_module_logging_setup(caplog: pytest.LogCaptureFixture): assert caplog.records[0].message == message -def test_root_logging_setup(caplog: pytest.LogCaptureFixture): +def test_logging_root(caplog: pytest.LogCaptureFixture): configure_logging() logger = logging.getLogger("") @@ -38,8 +40,10 @@ def test_root_logging_setup(caplog: pytest.LogCaptureFixture): assert caplog.records[0].message == message -def test_module_main_logging_setup(caplog: pytest.LogCaptureFixture): - configure_logging() +def test_logging_submodule(caplog: pytest.LogCaptureFixture): + config = {"loggers": {"tad": {"propagate": True}}} + + configure_logging(config=config) logger = logging.getLogger("tad.main") @@ -54,35 +58,46 @@ def test_module_main_logging_setup(caplog: pytest.LogCaptureFixture): assert caplog.records[0].message == message -def test_module_main_logging_with_custom_logging_setup(caplog: pytest.LogCaptureFixture): - configure_logging(level="ERROR") +def test_logging_config(caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv( + "LOGGING_CONFIG", + '{"loggers": { "tad": { "propagate": "True" }},"formatters": { "generic": { "fmt": "{name}: {message}"}}}', + ) - logger = logging.getLogger("tad.main") + settings = Settings() # type: ignore - message = "This is a test log message" + configure_logging(config=settings.LOGGING_CONFIG) + + logger = logging.getLogger("tad") + + message = "This is a test log message with other formatting" logger.debug(message) logger.info(message) logger.warning(message) logger.error(message) logger.critical(message) - assert len(caplog.records) == 2 + assert len(caplog.records) == 4 + +def test_logging_loglevel(caplog: pytest.LogCaptureFixture): + config = {"loggers": {"tad": {"propagate": True}}} -def test_enviroment_setup(caplog: pytest.LogCaptureFixture): - os.environ["LOGGING_CONFIG"] = '{"formatters": { "generic": { "fmt": "{name}: {message}"}}}' + configure_logging(config=config) + + os.environ["LOGGING_LEVEL"] = "ERROR" settings = Settings() # type: ignore - configure_logging(config=settings.LOGGING_CONFIG) + configure_logging(config=config, level=settings.LOGGING_LEVEL) logger = logging.getLogger("tad.main") - message = "This is a test log message with other formatting" + message = "This is a test log message with different logging level" logger.debug(message) logger.info(message) logger.warning(message) logger.error(message) logger.critical(message) - assert len(caplog.records) == 4 + assert len(caplog.records) == 2