summaryrefslogtreecommitdiff
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2005-01-13 08:23:56 +0000
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2005-01-13 08:23:56 +0000
commit2b2696ec340aa8cf185aa9d283e180b39b92df9c (patch)
tree96c486dde1d8e6b4edc6b31905261fb118a6a2d4 /Lib/logging
parent35791b6905dab528a6d0fda0dbdb2dca76fad458 (diff)
downloadcpython-2b2696ec340aa8cf185aa9d283e180b39b92df9c.tar.gz
Improved SysLogHandler error recovery (patch by Erik Forsberg)
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 19aefa64a3..672422b2e7 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: