]> granicus.if.org Git - python/commitdiff
Issue #8795: logging: Backported trunk fix for SysLogHandler and Unicode.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 24 May 2010 09:43:13 +0000 (09:43 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 24 May 2010 09:43:13 +0000 (09:43 +0000)
Lib/logging/handlers.py

index f05d1f629a36d40dbf076329113aa9ba41460eb2..756baf093b0969bb3d7bbc9d9dfff705a7b7f84b 100644 (file)
@@ -31,6 +31,11 @@ try:
     import codecs
 except ImportError:
     codecs = None
+try:
+    unicode
+    _unicode = True
+except NameError:
+    _unicode = False
 
 #
 # Some constants...
@@ -777,6 +782,11 @@ class SysLogHandler(logging.Handler):
             self.encodePriority(self.facility,
                                 self.mapPriority(record.levelname)),
                                 msg)
+        # Treat unicode messages as required by RFC 5424
+        if _unicode and type(msg) is unicode:
+            msg = msg.encode('utf-8')
+            if codecs:
+                msg = codecs.BOM_UTF8 + msg
         try:
             if self.unixsocket:
                 try: