Skip to content

Commit f6b1e40

Browse files
vsajipCAM-Gerlach
andauthored
gh-98307: Add docstring and documentation for SysLogHandler.createSocket (GH-98319)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 7b48d02 commit f6b1e40

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Doc/library/logging.handlers.rst

+11
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,17 @@ supports sending logging messages to a remote or local Unix syslog.
650650

651651
Closes the socket to the remote host.
652652

653+
.. method:: createSocket()
654+
655+
Tries to create a socket and, if it's not a datagram socket, connect it
656+
to the other end. This method is called during handler initialization,
657+
but it's not regarded as an error if the other end isn't listening at
658+
this point - the method will be called again when emitting an event, if
659+
but it's not regarded as an error if the other end isn't listening yet
660+
--- the method will be called again when emitting an event,
661+
if there is no socket at that point.
662+
663+
.. versionadded:: 3.11
653664

654665
.. method:: emit(record)
655666

Lib/logging/handlers.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -891,14 +891,21 @@ def _connect_unixsocket(self, address):
891891
raise
892892

893893
def createSocket(self):
894+
"""
895+
Try to create a socket and, if it's not a datagram socket, connect it
896+
to the other end. This method is called during handler initialization,
897+
but it's not regarded as an error if the other end isn't listening yet
898+
--- the method will be called again when emitting an event,
899+
if there is no socket at that point.
900+
"""
894901
address = self.address
895902
socktype = self.socktype
896903

897904
if isinstance(address, str):
898905
self.unixsocket = True
899906
# Syslog server may be unavailable during handler initialisation.
900907
# C's openlog() function also ignores connection errors.
901-
# Moreover, we ignore these errors while logging, so it not worse
908+
# Moreover, we ignore these errors while logging, so it's not worse
902909
# to ignore it also here.
903910
try:
904911
self._connect_unixsocket(address)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A :meth:`~logging.handlers.SysLogHandler.createSocket` method was added to
2+
:class:`~logging.handlers.SysLogHandler`.

0 commit comments

Comments
 (0)