diff --git a/CHANGELOG.md b/CHANGELOG.md index ed22e937..e0b7d80e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - accessing a multikey may lead to IndexError [#359](https://github.com/Draegerwerk/sdc11073/issues/359) +- fixed a bug where `log_prefix` can only be a string [#393](https://github.com/Draegerwerk/sdc11073/issues/393) ## [1.3.2] - 2024-03-18 diff --git a/src/sdc11073/loghelper.py b/src/sdc11073/loghelper.py index 3e38bcf4..ceb9bbba 100644 --- a/src/sdc11073/loghelper.py +++ b/src/sdc11073/loghelper.py @@ -60,7 +60,7 @@ def __init__(self, logger, prefix=None): def _process(self, msg, args, kwargs): try: - _msg = self.log_prefix + msg + _msg = f'{self.log_prefix}{msg}' except TypeError: _msg = msg diff --git a/tests/test_loghelper.py b/tests/test_loghelper.py index ef04e7b9..f4248a3c 100644 --- a/tests/test_loghelper.py +++ b/tests/test_loghelper.py @@ -1,5 +1,8 @@ import unittest import logging +import uuid +from unittest import mock + from sdc11073 import loghelper @@ -45,3 +48,15 @@ def test_logwatcher(self): records = lw2.getAllRecords() self.assertEqual(len(records), 1) self.assertRaises(loghelper.LogWatchException, lw2.check) + + def test_ident_parameter(self): + def _test_prefix(prefix): + adapter = loghelper.LoggerAdapter(logger=mock.MagicMock(), prefix=prefix) + msg = uuid.uuid4() + processed_msg = adapter._process(msg, (), ()) + self.assertEqual(f'{prefix or ""}{msg}', processed_msg) + + _test_prefix(1) + _test_prefix('1') + _test_prefix(mock.MagicMock()) + _test_prefix(None)