From 0eb2f90d01b2caef10d3d78798e252d378f728c4 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sun, 16 Oct 2022 06:13:37 +0100 Subject: [PATCH 1/5] gh-98307: Add docstring and documentation for SysLogHandler.createSocket --- Doc/library/logging.handlers.rst | 7 +++++++ Lib/logging/handlers.py | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst index f3b26e726aafc7..551a55915a0126 100644 --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -650,6 +650,13 @@ supports sending logging messages to a remote or local Unix syslog. Closes the socket to the remote host. + .. method:: createSocket() + + Tries to create a socket and, if it's not a datagram socket, connect it + to the other end. This method is called during handler initialization, + but it's not regarded as an error if the other end isn't listening at + this point - the method will be called again when emitting an event, if + there is no socket at that point. .. method:: emit(record) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index b4c5c1304b9752..dce0b0ac827a34 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -891,6 +891,13 @@ def _connect_unixsocket(self, address): raise def createSocket(self): + """ + Try to create a socket and, if it's not a datagram socket, connect it + to the other end. This method is called during handler initialization, + but it's not regarded as an error if the other end isn't listening at + this point - the method will be called again when emitting an event, if + there is no socket at that point. + """ address = self.address socktype = self.socktype @@ -898,7 +905,7 @@ def createSocket(self): self.unixsocket = True # Syslog server may be unavailable during handler initialisation. # C's openlog() function also ignores connection errors. - # Moreover, we ignore these errors while logging, so it not worse + # Moreover, we ignore these errors while logging, so it's not worse # to ignore it also here. try: self._connect_unixsocket(address) From d02a81a94c3d50ce0666ff3f1f30d954a52250c1 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sun, 16 Oct 2022 06:19:43 +0100 Subject: [PATCH 2/5] Add NEWS entry. --- .../next/Library/2022-10-16-06-18-59.gh-issue-98307.b2_CDu.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-10-16-06-18-59.gh-issue-98307.b2_CDu.rst diff --git a/Misc/NEWS.d/next/Library/2022-10-16-06-18-59.gh-issue-98307.b2_CDu.rst b/Misc/NEWS.d/next/Library/2022-10-16-06-18-59.gh-issue-98307.b2_CDu.rst new file mode 100644 index 00000000000000..3fe41d53c980b9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-16-06-18-59.gh-issue-98307.b2_CDu.rst @@ -0,0 +1,2 @@ +A :meth:`~logging.handlers.SysLogHandler.createSocket` method was added to +:class:`~logging.handlers.SysLogHandler`. From 483bea7ddb50479069c2873db053d899637b05a4 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sun, 16 Oct 2022 06:48:20 +0100 Subject: [PATCH 3/5] Improved phrasing Co-authored-by: C.A.M. Gerlach --- Lib/logging/handlers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index dce0b0ac827a34..9847104446eaf6 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -894,9 +894,9 @@ def createSocket(self): """ Try to create a socket and, if it's not a datagram socket, connect it to the other end. This method is called during handler initialization, - but it's not regarded as an error if the other end isn't listening at - this point - the method will be called again when emitting an event, if - there is no socket at that point. + but it's not regarded as an error if the other end isn't listening yet + --- the method will be called again when emitting an event, + if there is no socket at that point. """ address = self.address socktype = self.socktype From cee3a76424fb67a1e8078d79a2bcdc9e62fa5f1f Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sun, 16 Oct 2022 06:49:27 +0100 Subject: [PATCH 4/5] Improved phrasing and annotation added Co-authored-by: C.A.M. Gerlach --- Doc/library/logging.handlers.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst index 551a55915a0126..3524cc56980793 100644 --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -656,8 +656,12 @@ supports sending logging messages to a remote or local Unix syslog. to the other end. This method is called during handler initialization, but it's not regarded as an error if the other end isn't listening at this point - the method will be called again when emitting an event, if - there is no socket at that point. - + but it's not regarded as an error if the other end isn't listening yet + --- the method will be called again when emitting an event, + if there is no socket at that point. + + .. versionadded:: 3.11 + .. method:: emit(record) The record is formatted, and then sent to the syslog server. If exception From bf52ab12ac57512f716bdaa63de15fcf0c3f4852 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sun, 16 Oct 2022 06:52:33 +0100 Subject: [PATCH 5/5] Remove trailing whitespace. --- Doc/library/logging.handlers.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst index 3524cc56980793..d4429d3d0a4f73 100644 --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -659,9 +659,9 @@ supports sending logging messages to a remote or local Unix syslog. but it's not regarded as an error if the other end isn't listening yet --- the method will be called again when emitting an event, if there is no socket at that point. - + .. versionadded:: 3.11 - + .. method:: emit(record) The record is formatted, and then sent to the syslog server. If exception