Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion annotated_logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# https://test.pypi.org/project/annotated-logger/
# The dev versions in testpypi can then be pulled in to whatever project needed
# the new feature.
VERSION = "1.3.5" # pragma: no mutate
VERSION = "1.3.6" # pragma: no mutate

T = TypeVar("T")
P = ParamSpec("P")
Expand Down
3 changes: 1 addition & 2 deletions annotated_logger/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def filter(self, record: logging.LogRecord) -> bool:
"""Adjust the name of any fields that match a provided list if they exist."""
for new, old in self.targets.items():
if old in record.__dict__:
record.__dict__[new] = record.__dict__[old]
del record.__dict__[old]
record.__dict__[new] = record.__dict__.pop(old)
elif self.strict:
raise RenamerPlugin.FieldNotPresentError(old)
return True
Expand Down
8 changes: 8 additions & 0 deletions test/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ def test_logged_http_exception(self, annotated_logger_mock):


class TestRenamerPlugin:
@pytest.mark.parametrize("strict", [False, True])
def test_identity_mapping_preserves_message(self, strict):
record = logging.makeLogRecord({"msg": "hello %s", "args": ("world",)})
plugin = RenamerPlugin(strict=strict, msg="msg")

assert plugin.filter(record)
assert record.getMessage() == "hello world"

def test_joke_should_be_cheezy(self, annotated_logger_mock):
calc = Calculator(1, 9)
calc.divide()
Expand Down