Skip to content

Commit e59af55

Browse files
authored
bpo-29808: Do not fail in SysLogHandler constructor if syslog isn't available. (#695)
bpo-29808: SysLogHandler: Do not fail if initial connect to syslog failed. (cherry picked from commit 1b038e0)
1 parent 41b4a21 commit e59af55

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Lib/logging/handlers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,14 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
803803

804804
if isinstance(address, str):
805805
self.unixsocket = True
806-
self._connect_unixsocket(address)
806+
# Syslog server may be unavailable during handler initialisation.
807+
# C's openlog() function also ignores connection errors.
808+
# Moreover, we ignore these errors while logging, so it not worse
809+
# to ignore it also here.
810+
try:
811+
self._connect_unixsocket(address)
812+
except OSError:
813+
pass
807814
else:
808815
self.unixsocket = False
809816
if socktype is None:

0 commit comments

Comments
 (0)