Issue 16168: SysLogHandler constructor ignores socktype arg when address refers to a Unix Domain Socket (original) (raw)

_connect_unixsocket() (see below) does not use socktype value that was passed into SysLogHandler.init():

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)

SOCK_DGRAM causes log messages larger than about 2000 bytes to be dropped altogether on MacOS X 10.7.5 and to be truncated to 2081 bytes on Linux (tested with Amazon's linux, which is based on centos). This is quite unfortunate, since many exception tracebacks for production apps are larger than 2000 bytes, and it's paramount to capture the entire traceback in order to debug the issue. This limitation can be overcome if _connect_unixsocket() used the socktype arg value that was passed to SysLogHandler constructor.