]> granicus.if.org Git - python/commitdiff
amk pointed out that syslog may use UDP or TCP sockets.
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 26 Jan 2003 16:15:24 +0000 (16:15 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 26 Jan 2003 16:15:24 +0000 (16:15 +0000)
Update to try UDP, if that fails, try TCP.

Lib/logging/handlers.py

index 38711f8d4a3bbd45461870ff889e980cf4f0344e..bb3fe70de477657662ebf83cae3fb718f24e3eb6 100644 (file)
@@ -349,7 +349,13 @@ class SysLogHandler(logging.Handler):
         self.facility = facility
         if type(address) == types.StringType:
             self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
-            self.socket.connect(address)
+            # 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.unixsocket = 1
         else:
             self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)