mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-03 12:56:58 +00:00
Support prefix that is bytes.
This commit is contained in:
parent
ff7cf4d731
commit
0bef1eb4e2
@ -84,6 +84,17 @@ class Log(unittest.TestCase):
|
||||
self.assertEqual(self.messages[-2][0], '<LoggingObject0 #1>(pre1): hello')
|
||||
self.assertEqual(self.messages[-1][0], '<LoggingObject0 #1>(pre1): world')
|
||||
|
||||
def test_with_bytes_prefix(self):
|
||||
"""
|
||||
If bytes prefix is passed to PrefixingLogMixin.__init__, it is used in
|
||||
message rendering.
|
||||
"""
|
||||
obj = LoggingObject0("fac", prefix=b"pre1")
|
||||
obj.log("hello")
|
||||
obj.log("world")
|
||||
self.assertEqual(self.messages[-2][0], '<LoggingObject0 #1>(pre1): hello')
|
||||
self.assertEqual(self.messages[-1][0], '<LoggingObject0 #1>(pre1): world')
|
||||
|
||||
def test_no_prefix(self):
|
||||
"""
|
||||
If no prefix is passed to PrefixingLogMixin.__init__, it is not used in
|
||||
|
@ -68,6 +68,8 @@ class PrefixingLogMixin(nummedobj.NummedObj, LogMixin):
|
||||
LogMixin.__init__(self, facility, grandparentmsgid)
|
||||
|
||||
if prefix:
|
||||
if isinstance(prefix, bytes):
|
||||
prefix = prefix.decode("utf-8", errors="replace")
|
||||
self._prefix = "%s(%s): " % (self.__repr__(), prefix)
|
||||
else:
|
||||
self._prefix = "%s: " % (self.__repr__(),)
|
||||
|
Loading…
x
Reference in New Issue
Block a user