Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4cdb47

Browse files
committed
amk pointed out that syslog may use UDP or TCP sockets.
Update to try UDP, if that fails, try TCP.
1 parent cc4c50c commit f4cdb47

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/logging/handlers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,13 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):
349349
self.facility = facility
350350
if type(address) == types.StringType:
351351
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
352-
self.socket.connect(address)
352+
# syslog may require either DGRAM or STREAM sockets
353+
try:
354+
self.socket.connect(address)
355+
except socket.error:
356+
self.socket.close()
357+
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
358+
self.socket.connect(address)
353359
self.unixsocket = 1
354360
else:
355361
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

0 commit comments

Comments
 (0)