]> granicus.if.org Git - python/commitdiff
Closes #25664: handled logger names in Unicode.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Sat, 26 Dec 2015 12:21:47 +0000 (12:21 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Sat, 26 Dec 2015 12:21:47 +0000 (12:21 +0000)
Lib/logging/__init__.py

index fa9ebe8bf23ac02b0aadd31f6e17e0048cb205b5..caf151d1537e5c12f3b39007fce3e1de6d0d883c 100644 (file)
@@ -465,7 +465,15 @@ class Formatter(object):
         record.message = record.getMessage()
         if self.usesTime():
             record.asctime = self.formatTime(record, self.datefmt)
-        s = self._fmt % record.__dict__
+        try:
+            s = self._fmt % record.__dict__
+        except UnicodeDecodeError as e:
+            # Issue 25664. The logger name may be Unicode. Try again ...
+            try:
+                record.name = record.name.decode('utf-8')
+                s = self._fmt % record.__dict__
+            except UnicodeDecodeError:
+                raise e
         if record.exc_info:
             # Cache the traceback text to avoid converting it multiple times
             # (it's constant anyway)