From cb7ea2912ab5bdb8e6b3fadfb23a510825d36625 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 24 May 2010 09:43:13 +0000 Subject: [PATCH] Issue #8795: logging: Backported trunk fix for SysLogHandler and Unicode. --- Lib/logging/handlers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index f05d1f629a..756baf093b 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -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: -- 2.40.0