feat(Backend): PRWLR-3990 Add custom logging (#6)

* chore: PRWLR-4022 add django-cors-headers

* chore: PRWLR-4022 configure basic CORS

* feat: PRWLR-4022 add drf-spectacular and spec/docs endpoints

* build: PRWLR-4022 add basic docker development deployment

* chore: PRWLR-4022 update schema generation

* chore: PRWLR-4022 bump required Python version to 3.12

* feat: PRWLR-3990 add basic custom Django logging

* feat: PRWLR-3990 add tasks logger

* chore: PRWLR-3990 update API logging middleware to follow updated syntax

* docs: PRWLR-3990 add docstring for APILoggingMiddleware class

* chore: PRWLR-3990 add testing dependencies to poetry

* test(API): PRWLR-3990 add new middleware unit tests and base setup

* feat(API, Backend): PRWLR-3990 add NDJSONFormatter and transaction_id

* feat(API): PRWLR-3990 add dev/test model, views and urls

* chore(backend): PRWLR-3990 refactor logging settings and modules

* chore(backend): PRWLR-3990 add BackendLogger enum and refactor logging modules

* chore(backend): PRWLR-3990 refactor module importing

* style(backend): PRWLR-3990 remove extra endlines

* chore: PRWLR-3990 update poetry.lock

* chore: PRWLR-3990 run pre-commit
This commit is contained in:
Víctor Fernández Poyatos authored and GitHub committed 2024-07-05 10:13:04 -04:00
1 parent 30775373dc
commit 3a502c5b3d
16 files changed
+2240 -112

No files matched your search

View File
Whitespace-only changes.
+26
View File
@@ -0,0 +1,26 @@
from unittest.mock import patch, Mock, ANY
@patch("logging.getLogger")
def test_api_logger_middleware(mock_get_logger, client):
mock_logger = Mock()
mock_get_logger.side_effect = lambda name: mock_logger if name == "api" else Mock()
request_method = "GET"
request_path = "/this_path_does_not_exist"
api_logger = "api"
response = getattr(client, request_method.lower())(request_path)
mock_get_logger.assert_any_call(api_logger)
mock_logger.info.assert_called_once_with(
"",
extra={
"method": request_method,
"path": request_path,
"query_params": {},
"status_code": response.status_code,
"duration": ANY,
},
)
assert isinstance(mock_logger.info.call_args[1]["extra"]["duration"], float)