This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unify logging.handlers.SysLogHandler behavior with SocketHandlers
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cybergrind, python-dev, vinay.sajip
Priority: normal Keywords: patch

Created on 2021-06-02 18:31 by cybergrind, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26490 merged python-dev, 2021-06-02 19:06
Messages (6)
msg394932 - (view) Author: Kirill Pinchuk (cybergrind) * Date: 2021-06-02 18:31
Probably we should make the behavior of SysLogHandler consistent with other Socket handlers.

Right now SocketHandler and DatagramHandler implement such behavior:

1) on `close` set `self.socket = None`
2) when trying to send - make socket when it is None


SysLogHandler doesn't implement this behavior and when you close the socket for some reason (eg. restart of uWSGI server on code change) it leaves it in the closed state, then raises an error when you try to send any message because it is closed

```
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.9/logging/handlers.py", line 959, in emit
    self.socket.sendto(msg, self.address)
OSError: [Errno 9] Bad file descriptor

```
msg394935 - (view) Author: Kirill Pinchuk (cybergrind) * Date: 2021-06-02 18:55
UPD: right now it has reconnection logic for unixsocket but not for tcp/udp
msg394998 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2021-06-03 13:06
> right now it has reconnection logic for unixsocket but not for tcp/udp

Should it not have UDP/TCP supported as well as domain sockets, before being reviewed?
msg394999 - (view) Author: Kirill Pinchuk (cybergrind) * Date: 2021-06-03 13:17
Oh, sorry bad wording.

The current implementation has reconnection logic only for UNIX sockets
The patch adds reconnection logic for UDP/TCP sockets as well.


I've done it with minimal changes to the existing code to accomplish that. And probably it can be merged.

But in general, it looks like we can refactor SysLogHandler to inherit from SocketHandler. Not sure if it should be done in this PR or better to create separate?
msg395168 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2021-06-05 15:47
> Oh, sorry bad wording.

OK, I see. Will take a look soon.

> it looks like we can refactor SysLogHandler to inherit from SocketHandler. Not sure if it should be done in this PR

Better a separate PR for that, I feel.

Removing the older Pythons from the issue, as this is an enhancement request.
msg399005 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2021-08-05 13:58
New changeset 3d315c311676888201f4a3576e4ee3698684a3a2 by Kirill Pinchuk in branch 'main':
bpo-44291: Fix reconnection in logging.handlers.SysLogHandler (GH-26490)
https://github.com/python/cpython/commit/3d315c311676888201f4a3576e4ee3698684a3a2
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88457
2021-08-05 17:29:37vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-08-05 13:58:25vinay.sajipsetmessages: + msg399005
2021-06-05 15:47:48vinay.sajipsetmessages: + msg395168
versions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
2021-06-03 13:17:31cybergrindsetmessages: + msg394999
2021-06-03 13:06:17vinay.sajipsetnosy: + vinay.sajip
messages: + msg394998
2021-06-02 19:06:26python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request25086
stage: patch review
2021-06-02 18:55:54cybergrindsetmessages: + msg394935
2021-06-02 18:31:52cybergrindcreate