I have a process sending logs to a syslog server over TCP using logging.SyslogHandler. Unfortunately, if the syslog server is restarted for some reason, the process stops sending logs and is unable to re-establish the connection.
I was wondering if anyone knows of a way to overcome this behaviour and force logging.SyslogHandler to re-establish the connection.
Code to use the handler would be something like:
import logging
import logging.handlers
import logging.config
logging.config.fileConfig('logging.cfg')
logging.debug("debug log message")
logging.cfg:
[loggers]
keys=root,remote
[handlers]
keys=local,remote
[logger_remote]
qualname=remote
level=INFO
handlers=remote
[logger_root]
qualname=root
level=DEBUG
handlers=local
[handler_local]
class=handlers.StreamHandler
level=DEBUG
formatter=local
args=(sys.stdout,)
[handler_remote]
class=handlers.SysLogHandler
level=DEBUG
formatter=remote
args=(('localhost', 514), handlers.SysLogHandler.LOG_USER, 1)
[formatters]
keys=local,remote
[formatter_local]
format=%(module)s %(levelname)s %(message)s
[formatter_remote]
format=%(asctime)s %(message)s
The error I keep getting after the syslog server restarts is:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/logging/handlers.py", line 866, in emit
self.socket.sendall(msg)
File "/usr/local/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 32] Broken pipe
I would appreciate any insights. Thanks!