我使用SysLogHandler在我的日志配置文件中。
如rsyslog
正在我的linux机器上运行,我想使用socket.SOCK_STREAM
如socktype
SysLogHandler
的关键字参数实例。 documentation确实说:
To open a TCP socket (for use with the newer syslog daemons such as rsyslog), specify a value of socket.SOCK_STREAM.
但是当我添加处理程序时,如下所示:
log.addHandler(logging.handlers.SysLogHandler(address='/dev/log',
facility='mathmaker',
socktype=socket.SOCK_STREAM))
我收到此错误:
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
虽然看起来 rsyslog 正在监听/dev/log: lsof | grep rsyslog
显示:
rsyslogd 8090 syslog 0u unix 0xffff8800b413ce00 0t0 2739240 /dev/log
最佳答案
看起来不可能对 unix 套接字使用 socket.SOCK_STREAM。
我认为我读文档的速度太快了,因为:
for use with the newer syslog daemons such as rsyslog
并不意味着 rsyslog 配置为使用 TCP 套接字(只是可能如此)。
关于python - 在日志记录配置中使用socket.SOCK_STREAM时为"Protocol wrong type for socket",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36777090/