在将CherryPy与systemd套接字单元一起使用时记录客户端IP地址

时间:2018-06-19 18:35:17

标签: logging cherrypy systemd

当我将HelloWorld CherryPy示例作为独立进程运行时,它在其日志中发出有意义的客户端IP地址。但是,如果我运行与systemd套接字激活的服务相同的示例,则日志不再显示客户端IP地址,而是显示与套接字关联的::400:0:0:0%3617728304之类的内容。使用systemd套接字单元管理套接字时,如何获取正确的客户端IP地址记录?

hello.py

import cherrypy
class HelloWorld(object):
    def index(self):
        return "Hello World!"
    index.exposed = True
cherrypy.config.update({'server.socket_host': '0.0.0.0',
                        'server.socket_port': 8080,
                       })
cherrypy.quickstart(HelloWorld())

cherrypy-test.socket

[Socket]
ListenStream=8080
[Install]
WantedBy=sockets.target

cherrypy-test.service

[Service]
ExecStart=/usr/bin/python /opt/cherrypy_client_IP/hello.py

未从systemd套接字单元运行时的示例日志行

192.168.6.133 - - [19/Jun/2018:11:20:34] "GET / HTTP/1.1" 200 12 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"

从systemd套接字单元运行时的示例日志行

::400:0:0:0%3617728304 - - [19/Jun/2018:11:26:55] "GET / HTTP/1.1" 200 12 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"

0 个答案:

没有答案