django runserver的这个特定日志输出来自何处

Tre*_*ewq 6 python django logging

我正在学习有关在Python记录,所以我试图找出其中的源代码,当你这个具体的输出格式的行部分:"GET /dashboard/ HTTP/1.1" 200 249176?另外,249176是什么意思?

我没有问题,这个问题是为了满足我的好奇心.

我真的在寻找这个logrecord的格式化程序.我也没有看到它来自哪个loghandler(也许这根本不是来自日志记录模块,它只是一个打印命令).我搜索了源代码,无法找到它的来源,并希望有一个链接到源代码.

以下是我运行代码时会发生的情况.

September 05, 2013 - 05:38:50
Django version 1.5.1, using settings 'dapi.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[05/Sep/2013 05:38:57] "GET /dashboard/ HTTP/1.1" 200 249176
[05/Sep/2013 05:38:58] "GET /static/plugins/uniform/css/uniform.default.css HTTP/1.1" 304 0
[05/Sep/2013 05:38:58] "GET /static/plugins/bootstrap-daterangepicker/daterangepicker.css HTTP/1.1" 304 0
Run Code Online (Sandbox Code Playgroud)

ale*_*cxe 7

这个数字是响应内容的长度,换句话说:发送的字节数。

这个输出基本上来自wsgirefsimple_server(它基于BaseHTTPServer),它是 django 的class WSGIRequestHandler,如下(source)。

$ cat django/core/servers/basehttp.py

   ... ignored here ...

class WSGIRequestHandler(simple_server.WSGIRequestHandler):

    def log_message(self, format, *args):
        
        ...... the access log comes here ......

        # sys.stderr.write(msg)
        # level(format, *args, extra=extra)
Run Code Online (Sandbox Code Playgroud)

log_request()函数实际上是在记录代码和内容大小:

日志请求([代码[,大小]])

记录已接受(成功)的请求。code 应指定与响应关联的数字 HTTP 代码。如果响应的大小可用,则应将其作为大小参数传递。

有兴趣的可以看看BaseHTTPServerpypy的实现:https ://bitbucket.org/pypy/pypy/src/9d88b4875d6e/lib-python/2.7/BaseHTTPServer.py

也可以看看: