diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-09-27 17:18:28 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-09-27 17:18:28 (GMT) |
commit | 5421f35d5e215a69382f0c195c0c39c8b541eca7 (patch) | |
tree | 113a860e9f3758506e285490e0061ea472684469 /Lib/logging | |
parent | 55798896a4bd3f294755523d8237a56cacc4bf5c (diff) | |
download | cpython-5421f35d5e215a69382f0c195c0c39c8b541eca7.zip cpython-5421f35d5e215a69382f0c195c0c39c8b541eca7.tar.gz cpython-5421f35d5e215a69382f0c195c0c39c8b541eca7.tar.bz2 |
logging: added support for Unix domain sockets to SocketHandler and DatagramHandler.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/handlers.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 0ae6e45..b0b0a16 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -494,6 +494,10 @@ class SocketHandler(logging.Handler): logging.Handler.__init__(self) self.host = host self.port = port + if port is None: + self.address = host + else: + self.address = (host, port) self.sock = None self.closeOnError = False self.retryTime = None @@ -509,7 +513,13 @@ class SocketHandler(logging.Handler): A factory method which allows subclasses to define the precise type of socket they want. """ - return socket.create_connection((self.host, self.port), timeout=timeout) + if self.port is not None: + result = socket.create_connection(self.address, timeout=timeout) + else: + result = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + result.settimeout(timeout) + result.connect(self.address) + return result def createSocket(self): """ @@ -643,7 +653,11 @@ class DatagramHandler(SocketHandler): The factory method of SocketHandler is here overridden to create a UDP socket (SOCK_DGRAM). """ - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + if self.port is None: + family = socket.AF_UNIX + else: + family = socket.AF_INET + s = socket.socket(family, socket.SOCK_DGRAM) return s def send(self, s): @@ -656,7 +670,7 @@ class DatagramHandler(SocketHandler): """ if self.sock is None: self.createSocket() - self.sock.sendto(s, (self.host, self.port)) + self.sock.sendto(s, self.address) class SysLogHandler(logging.Handler): """ |