zezollo
zezollo

Reputation: 5017

"Protocol wrong type for socket" when using socket.SOCK_STREAM in logging configuration

I use SysLogHandler in my logging configuration file.

As rsyslog is running on my linux box, I want to use socket.SOCK_STREAM as socktype keyword argument of the SysLogHandler instance. The documentation says indeed:

To open a TCP socket (for use with the newer syslog daemons such as rsyslog), specify a value of socket.SOCK_STREAM.

But when I add the handler, like this:

log.addHandler(logging.handlers.SysLogHandler(address='/dev/log',
                                          facility='mathmaker',
                                          socktype=socket.SOCK_STREAM))

I get this error:

  File "/home/zezo/dev/myapp/myapp", line 52, in <module>
    socktype=socket.SOCK_STREAM))
  File "/usr/lib/python3.4/logging/handlers.py", line 803, in __init__
    self._connect_unixsocket(address)
  File "/usr/lib/python3.4/logging/handlers.py", line 820, in _connect_unixsocket
    self.socket.connect(address)
OSError: [Errno 91] Protocol wrong type for socket

Though it seems like rsyslog is listening to /dev/log: lsof | grep rsyslog shows:

rsyslogd   8090           syslog    0u     unix 0xffff8800b413ce00      0t0    2739240 /dev/log

Upvotes: 1

Views: 18245

Answers (1)

zezollo
zezollo

Reputation: 5017

Looks like it's not possible to use socket.SOCK_STREAM for a unix socket.

I think I have read the doc too fast, as:

for use with the newer syslog daemons such as rsyslog

does not mean rsyslog is configured to use TCP sockets (only that it could be).

Upvotes: 2

Related Questions