Skip to content

Commit

Permalink
Remove structlog (#119)
Browse files Browse the repository at this point in the history
* Replace structlog with stdlib logger

* Uninstall structlog
  • Loading branch information
4c0n authored Jan 21, 2025
1 parent 1c33192 commit dddfb9c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
5 changes: 2 additions & 3 deletions meldingen_core/actions/melding.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import logging
from abc import ABCMeta, abstractmethod
from datetime import datetime, timedelta
from typing import Any, Generic, TypeVar, override

import structlog

from meldingen_core.actions.base import BaseCreateAction, BaseCRUDAction, BaseListAction, BaseRetrieveAction
from meldingen_core.classification import ClassificationNotFoundException, Classifier
from meldingen_core.exceptions import NotFoundException
Expand All @@ -12,7 +11,7 @@
from meldingen_core.statemachine import BaseMeldingStateMachine, MeldingTransitions
from meldingen_core.token import BaseTokenGenerator, TokenVerifier

log = structlog.get_logger()
log = logging.getLogger(__name__)

T = TypeVar("T", bound=Melding)
T_co = TypeVar("T_co", covariant=True, bound=Melding)
Expand Down
22 changes: 2 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ license = "EUPL-2.1"
[tool.poetry.dependencies]
python = "^3.12"
plugfs = {git = "https://github.com/amsterdam/plugfs"}
structlog = "^24.1.0"

[tool.poetry.group.dev.dependencies]
anyio = "^4.6.2"
Expand Down
14 changes: 8 additions & 6 deletions tests/test_actions/test_melding_actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
from datetime import datetime, timedelta
from unittest.mock import AsyncMock, Mock

import pytest
from structlog.testing import capture_logs
from _pytest.logging import LogCaptureFixture

from meldingen_core.actions.melding import (
MeldingAddAttachmentsAction,
Expand Down Expand Up @@ -45,7 +46,7 @@ async def test_melding_create_action() -> None:


@pytest.mark.anyio
async def test_melding_create_action_with_classification_not_found() -> None:
async def test_melding_create_action_with_classification_not_found(caplog: LogCaptureFixture) -> None:
classifier = AsyncMock(Classifier, side_effect=ClassificationNotFoundException)
state_machine = Mock(BaseMeldingStateMachine)
repository = Mock(BaseMeldingRepository)
Expand All @@ -54,12 +55,13 @@ async def test_melding_create_action_with_classification_not_found() -> None:
)
melding = Melding("text")

with capture_logs() as captured_logs:
with caplog.at_level(logging.ERROR):
await action(melding)

assert len(captured_logs) == 1
assert captured_logs[0].get("log_level") == "error"
assert captured_logs[0].get("event") == "Classifier failed to find classification!"
assert len(caplog.records) == 1
assert caplog.records[0].levelname == "ERROR"
assert caplog.records[0].message == "Classifier failed to find classification!"

state_machine.transition.assert_not_awaited()


Expand Down

0 comments on commit dddfb9c

Please sign in to comment.