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: SysLogHandler closes TCP connection after first message
Type: Stage:
Components: Library (Lib) Versions: Python 3.4, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Omer.Katz, vinay.sajip
Priority: normal Keywords:

Created on 2014-06-19 08:12 by Omer.Katz, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg220961 - (view) Author: Omer Katz (Omer.Katz) * Date: 2014-06-19 08:12
import logging
import logging.handlers
import socket

logger = logging.getLogger('mylogger')
handler = logging.handlers.SysLogHandler(('****', logging.handlers.SYSLOG_TCP_PORT), socktype=socket.SOCK_STREAM)
formatter = logging.Formatter('%(name)s: [%(levelname)s] %(message)s')
handler.setFormatter(formatter)

logger.addHandler(handler)

logger.info("TEST 1")
logger.info("TEST 2")

I have verified that this code only sends 'TEST 1' to Splunk and syslog-ng on both Python 2.7 and Python 3.4. After that, the connection appears closed. UDP on the other hand works just fine.
msg220993 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2014-06-19 15:30
Some information appears to be missing from your snippet: the default logger level is WARNING, so no INFO messages would be expected.

Have you set logging.raiseExceptions to a False value? Are you sure that no network error is occurring? How can you be sure the other end isn't closing the connection? I ask these questions, because there is no code called to explicitly close the socket, unless an error occurs.

Also, no one else has ever reported this problem, and this code hasn't changed in a long time, IIRC.
msg221349 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2014-06-23 12:00
The default for syslog-ng's so_keepalive() option is No (don't keep the socket open). Since you haven't responded with more information, I'll assume that you're using this default setting, and that syslog-ng is terminating the connection. Reopen if you have information to the contrary.
History
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 66006
2014-06-23 12:00:50vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg221349
2014-06-19 15:30:13vinay.sajipsetmessages: + msg220993
2014-06-19 13:59:40r.david.murraysetnosy: + vinay.sajip
2014-06-19 08:12:08Omer.Katzcreate