Improved SysLogHandler error recovery (patch by Erik Forsberg)
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 19aefa6..672422b 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -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: