]> granicus.if.org Git - python/commitdiff
Brought excluded code into the scope of a try block in SysLogHandler.emit().
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Sat, 1 Nov 2014 19:58:47 +0000 (19:58 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Sat, 1 Nov 2014 19:58:47 +0000 (19:58 +0000)
Lib/logging/handlers.py
Misc/NEWS

index b371824054370a9449f722e90f3ac73d474a9677..43cbb55c327bdd9c762b8a80848a32d0212cf514 100644 (file)
@@ -879,21 +879,21 @@ class SysLogHandler(logging.Handler):
         The record is formatted, and then sent to the syslog server. If
         exception information is present, it is NOT sent to the server.
         """
-        msg = self.format(record)
-        if self.ident:
-            msg = self.ident + msg
-        if self.append_nul:
-            msg += '\000'
-
-        # We need to convert record level to lowercase, maybe this will
-        # change in the future.
-        prio = '<%d>' % self.encodePriority(self.facility,
-                                            self.mapPriority(record.levelname))
-        prio = prio.encode('utf-8')
-        # Message is a string. Convert to bytes as required by RFC 5424
-        msg = msg.encode('utf-8')
-        msg = prio + msg
         try:
+            msg = self.format(record)
+            if self.ident:
+                msg = self.ident + msg
+            if self.append_nul:
+                msg += '\000'
+
+            # We need to convert record level to lowercase, maybe this will
+            # change in the future.
+            prio = '<%d>' % self.encodePriority(self.facility,
+                                                self.mapPriority(record.levelname))
+            prio = prio.encode('utf-8')
+            # Message is a string. Convert to bytes as required by RFC 5424
+            msg = msg.encode('utf-8')
+            msg = prio + msg
             if self.unixsocket:
                 try:
                     self.socket.send(msg)
index 9f9155dcf1cff6e69825d80420431224701c19a3..97bb398e3af7844ed80edaa4a246fdf002426f85 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #22776: Brought excluded code into the scope of a try block in
+  SysLogHandler.emit().
 - Issue #22665: Add missing get_terminal_size and SameFileError to
   shutil.__all__.