Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e917052

Browse files
committed
Issue #17795: Reverted backwards-incompatible change in SysLogHandler with Unix domain sockets.
1 parent 25187e6 commit e917052

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

Lib/logging/handlers.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved.
1+
# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved.
22
#
33
# Permission to use, copy, modify, and distribute this software and its
44
# documentation for any purpose and without fee is hereby granted,
@@ -18,7 +18,7 @@
1818
Additional handlers for the logging package for Python. The core package is
1919
based on PEP 282 and comments thereto in comp.lang.python.
2020
21-
Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
21+
Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved.
2222
2323
To use, simply 'import logging.handlers' and log away!
2424
"""
@@ -767,7 +767,7 @@ class SysLogHandler(logging.Handler):
767767
}
768768

769769
def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
770-
facility=LOG_USER, socktype=socket.SOCK_DGRAM):
770+
facility=LOG_USER, socktype=None):
771771
"""
772772
Initialize a handler.
773773
@@ -786,18 +786,37 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
786786
self._connect_unixsocket(address)
787787
else:
788788
self.unixsocket = False
789+
if socktype is None:
790+
socktype = socket.SOCK_DGRAM
789791
self.socket = socket.socket(socket.AF_INET, socktype)
790792
if socktype == socket.SOCK_STREAM:
791793
self.socket.connect(address)
794+
self.socktype = socktype
792795
self.formatter = None
793796

794797
def _connect_unixsocket(self, address):
795-
self.socket = socket.socket(socket.AF_UNIX, self.socktype)
798+
use_socktype = self.socktype
799+
if use_socktype is None:
800+
use_socktype = socket.SOCK_DGRAM
801+
self.socket = socket.socket(socket.AF_UNIX, use_socktype)
796802
try:
797803
self.socket.connect(address)
804+
# it worked, so set self.socktype to the used type
805+
self.socktype = use_socktype
798806
except socket.error:
799807
self.socket.close()
800-
raise
808+
if self.socktype is not None:
809+
# user didn't specify falling back, so fail
810+
raise
811+
use_socktype = socket.SOCK_STREAM
812+
self.socket = socket.socket(socket.AF_UNIX, use_socktype)
813+
try:
814+
self.socket.connect(address)
815+
# it worked, so set self.socktype to the used type
816+
self.socktype = use_socktype
817+
except socket.error:
818+
self.socket.close()
819+
raise
801820

802821
def encodePriority(self, facility, priority):
803822
"""

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #17795: Reverted backwards-incompatible change in SysLogHandler with
40+
Unix domain sockets.
41+
3942
- Issue #17555: Fix ForkAwareThreadLock so that size of after fork
4043
registry does not grow exponentially with generation of process.
4144

0 commit comments

Comments
 (0)