回到顶部

阅读目录

django runserver log add client(request) ip

source: 

https://code.djangoproject.com/ticket/16301

django source code location ( django 2.2 ):

..\Lib\site-packages\django\core\servers\basehttp.py ( WSGIRequestHandler -> log_message)

class WSGIRequestHandler(simple_server.WSGIRequestHandler):
    protocol_version = 'HTTP/1.1'

    def address_string(self):
        # Short-circuit parent method to not call socket.getfqdn
        return self.client_address[0]

    def log_message(self, format, *args):
        extra = {
            'request': self.request,
            'server_time': self.log_date_time_string(),
        }

changed code:

class WSGIRequestHandler(simple_server.WSGIRequestHandler):
    protocol_version = 'HTTP/1.1'

    def address_string(self):
        # Short-circuit parent method to not call socket.getfqdn
        return self.client_address[0]

    def log_message(self, format, *args):
        extra = {
            'request': self.request,
            'server_time': self.log_date_time_string() + " - %s" % self.client_address[0],
        }

django runserver log:

System check identified no issues (0 silenced).
May 04, 2020 - 20:52:11
Django version 2.2.4, using settings 'django2.settings'
Starting development server at http://192.168.91.116:8002/
Quit the server with CTRL-BREAK.
[04/May/2020 20:52:25 - 192.168.91.116] "GET /bus/baidu HTTP/1.1" 200 611
[04/May/2020 20:52:25 - 192.168.91.116] "GET /static/js/my.js HTTP/1.1" 200 2950
[04/May/2020 20:52:25 - 192.168.91.116] "GET /static/css/my.css HTTP/1.1" 200 859
[04/May/2020 20:52:33 - 192.168.91.38] "GET /bus/baidu HTTP/1.1" 200 611

 

^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!

前一篇: 作息时间约法三章
下一篇: Android chrome 开启底部工具栏