[Python-checkins] python/dist/src/Lib/logging handlers.py, 1.19, 1.20

vsajip at users.sourceforge.net vsajip at users.sourceforge.net
Thu Jan 13 09:23:59 CET 2005


Update of /cvsroot/python/python/dist/src/Lib/logging
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4147

Modified Files:
	handlers.py 
Log Message:
Improved SysLogHandler error recovery (patch by Erik Forsberg)

Index: handlers.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/logging/handlers.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- handlers.py	3 Oct 2004 19:12:07 -0000	1.19
+++ handlers.py	13 Jan 2005 08:23:56 -0000	1.20
@@ -555,14 +555,7 @@
         self.address = address
         self.facility = facility
         if type(address) == types.StringType:
-            self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
-            # syslog may require either DGRAM or STREAM sockets
-            try:
-                self.socket.connect(address)
-            except socket.error:
-                self.socket.close()
-                self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-            self.socket.connect(address)
+            self._connect_unixsocket(address)
             self.unixsocket = 1
         else:
             self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -570,6 +563,16 @@
 
         self.formatter = None
 
+    def _connect_unixsocket(self, address):
+        self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+        # syslog may require either DGRAM or STREAM sockets
+        try:
+            self.socket.connect(address)
+        except socket.error:
+            self.socket.close()
+            self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.socket.connect(address)
+
     # curious: when talking to the unix-domain '/dev/log' socket, a
     #   zero-terminator seems to be required.  this string is placed
     #   into a class variable so that it can be overridden if
@@ -615,7 +618,11 @@
             msg)
         try:
             if self.unixsocket:
-                self.socket.send(msg)
+                try:
+                    self.socket.send(msg)
+                except socket.error:
+                    self._connect_unixsocket(self.address)
+                    self.socket.send(msg)
             else:
                 self.socket.sendto(msg, self.address)
         except:



More information about the Python-checkins mailing list