diff --git a/annotated_logger/__init__.py b/annotated_logger/__init__.py index be63003..7e64339 100644 --- a/annotated_logger/__init__.py +++ b/annotated_logger/__init__.py @@ -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") diff --git a/annotated_logger/plugins.py b/annotated_logger/plugins.py index a73ad54..bd92166 100644 --- a/annotated_logger/plugins.py +++ b/annotated_logger/plugins.py @@ -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 diff --git a/test/test_plugins.py b/test/test_plugins.py index 1f144e8..2628915 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -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()