Skip to content

Commit

Permalink
allow any type for log prefix v1 (Draegerwerk#394)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the title above -->
<!--- Link the corresponding issues after you created the pull request
-->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [x] I have updated the [changelog](../CHANGELOG.md) accordingly.
- [x] I have added tests to cover my changes.
  • Loading branch information
leon1995 authored Sep 16, 2024
1 parent 6473828 commit c3e989a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/sdc11073/loghelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions tests/test_loghelper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import unittest
import logging
import uuid
from unittest import mock

from sdc11073 import loghelper


Expand Down Expand Up @@ -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)

0 comments on commit c3e989a

Please sign in to comment.