]> granicus.if.org Git - python/commitdiff
Issue #7077: logging: SysLogHandler now treats Unicode as per RFC 5424.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Wed, 21 Oct 2009 20:22:14 +0000 (20:22 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Wed, 21 Oct 2009 20:22:14 +0000 (20:22 +0000)
Lib/logging/handlers.py
Misc/NEWS

index bdf82aff6e98d276517361be1855b35051453918..d752063c1bf5762bb987a55b579b4219665e9a2d 100644 (file)
@@ -31,6 +31,11 @@ try:
     import codecs
 except ImportError:
     codecs = None
+try:
+    unicode
+    _unicode = True
+except NameError:
+    _unicode = False
 
 #
 # Some constants...
@@ -779,6 +784,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:
index 49c739f77db49684abe8136c9f52ae416aef3839..6946706d09e5168f563b4883b9db2864c4cb598b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -418,6 +418,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #7077: logging: SysLogHandler now treats Unicode as per RFC 5424.
+
 - Issue #7099: Decimal.is_normal now returns True for numbers with exponent
   larger than emax.