diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2005-01-13 08:23:56 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2005-01-13 08:23:56 (GMT) |
commit | a1974c1459a424fdc9d8bbce55500f6006d0297d (patch) | |
tree | e487ad1de7bc094868dd2a69cb312d154dca801d | |
parent | 0af3ade6aa597a8871dbb62c312a8ab62e3cd309 (diff) | |
download | cpython-a1974c1459a424fdc9d8bbce55500f6006d0297d.zip cpython-a1974c1459a424fdc9d8bbce55500f6006d0297d.tar.gz cpython-a1974c1459a424fdc9d8bbce55500f6006d0297d.tar.bz2 |
Improved SysLogHandler error recovery (patch by Erik Forsberg)
-rw-r--r-- | Lib/logging/handlers.py | 25 |
1 files changed, 16 insertions, 9 deletions
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 @@ class SysLogHandler(logging.Handler): 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 @@ class SysLogHandler(logging.Handler): 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 @@ class SysLogHandler(logging.Handler): 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: |