[Python-checkins] cpython (merge 3.3 -> default): Closes #17795: Reverted backwards-incompatible change in SysLogHandler with
vinay.sajip
python-checkins at python.org
Mon Apr 22 11:14:31 CEST 2013
http://hg.python.org/cpython/rev/9c0a677dbbc0
changeset: 83491:9c0a677dbbc0
parent: 83487:dac847938326
parent: 83490:d03784713786
user: Vinay Sajip <vinay_sajip at yahoo.co.uk>
date: Mon Apr 22 10:14:12 2013 +0100
summary:
Closes #17795: Reverted backwards-incompatible change in SysLogHandler with Unix domain sockets.
files:
Lib/logging/handlers.py | 31 +++++++++++++++++++++++++---
Misc/NEWS | 3 ++
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -758,13 +758,17 @@
}
def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
- facility=LOG_USER, socktype=socket.SOCK_DGRAM):
+ facility=LOG_USER, socktype=None):
"""
Initialize a handler.
If address is specified as a string, a UNIX socket is used. To log to a
local syslogd, "SysLogHandler(address="/dev/log")" can be used.
- If facility is not specified, LOG_USER is used.
+ If facility is not specified, LOG_USER is used. If socktype is
+ specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific
+ socket type will be used. For Unix sockets, you can also specify a
+ socktype of None, in which case socket.SOCK_DGRAM will be used, falling
+ back to socket.SOCK_STREAM.
"""
logging.Handler.__init__(self)
@@ -777,18 +781,37 @@
self._connect_unixsocket(address)
else:
self.unixsocket = False
+ if socktype is None:
+ socktype = socket.SOCK_DGRAM
self.socket = socket.socket(socket.AF_INET, socktype)
if socktype == socket.SOCK_STREAM:
self.socket.connect(address)
+ self.socktype = socktype
self.formatter = None
def _connect_unixsocket(self, address):
- self.socket = socket.socket(socket.AF_UNIX, self.socktype)
+ use_socktype = self.socktype
+ if use_socktype is None:
+ use_socktype = socket.SOCK_DGRAM
+ self.socket = socket.socket(socket.AF_UNIX, use_socktype)
try:
self.socket.connect(address)
+ # it worked, so set self.socktype to the used type
+ self.socktype = use_socktype
except OSError:
self.socket.close()
- raise
+ if self.socktype is not None:
+ # user didn't specify falling back, so fail
+ raise
+ use_socktype = socket.SOCK_STREAM
+ self.socket = socket.socket(socket.AF_UNIX, use_socktype)
+ try:
+ self.socket.connect(address)
+ # it worked, so set self.socktype to the used type
+ self.socktype = use_socktype
+ except OSError:
+ self.socket.close()
+ raise
def encodePriority(self, facility, priority):
"""
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -49,6 +49,9 @@
Library
-------
+- Issue #17795: Reverted backwards-incompatible change in SysLogHandler with
+ Unix domain sockets.
+
- Issue #16694: Add a pure Python implementation of the operator module.
Patch by Zachary Ware.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list