Skip to content

Commit 5a8a67a

Browse files
committed
logging: handle StreamHandler representaton of stream with int name
When debugging uwsgi logging issues with python3.7 i got this: Traceback (most recent call last): File "/usr/lib/python3.7/logging/__init__.py", line 269, in _after_at_fork_weak_calls _at_fork_weak_calls('release') File "/usr/lib/python3.7/logging/__init__.py", line 261, in _at_fork_weak_calls method_name, "method:", err, file=sys.stderr) File "/usr/lib/python3.7/logging/__init__.py", line 1066, in __repr__ name = name + ' ' TypeError: unsupported operand type(s) for +: 'int' and 'str'
1 parent 1bf8845 commit 5a8a67a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Lib/logging/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,8 @@ def setStream(self, stream):
11201120
def __repr__(self):
11211121
level = getLevelName(self.level)
11221122
name = getattr(self.stream, 'name', '')
1123+
# bpo-36015: name can be an int
1124+
name = str(name)
11231125
if name:
11241126
name += ' '
11251127
return '<%s %s(%s)>' % (self.__class__.__name__, name, level)

Lib/test/test_logging.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,10 @@ class TestStreamHandler(logging.StreamHandler):
743743
def handleError(self, record):
744744
self.error_record = record
745745

746+
class StreamWithIntName(object):
747+
level = logging.NOTSET
748+
name = 2
749+
746750
class StreamHandlerTest(BaseTest):
747751
def test_error_handling(self):
748752
h = TestStreamHandler(BadStream())
@@ -780,6 +784,10 @@ def test_stream_setting(self):
780784
actual = h.setStream(old)
781785
self.assertIsNone(actual)
782786

787+
def test_can_represent_stream_with_int_name(self):
788+
h = logging.StreamHandler(StreamWithIntName())
789+
self.assertEqual(repr(h), '<StreamHandler 2 (NOTSET)>')
790+
783791
# -- The following section could be moved into a server_helper.py module
784792
# -- if it proves to be of wider utility than just test_logging
785793

0 commit comments

Comments
 (0)