【问题标题】:where does this specific log output from django runserver come fromdjango runserver 的这个特定日志输出来自哪里
【发布时间】:2013-09-05 10:43:31
【问题描述】:

我正在学习有关登录 python 的知识,因此我试图找出源代码中的哪个部分是当您获得此特定输出时格式化该行的部分:"GET /dashboard/ HTTP/1.1" 200 249176?还有,249176是什么意思?

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

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

这是我运行代码时发生的情况。

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

【问题讨论】:

  • 注意:这是“Web 服务器的日志记录”而不是“Python 中的日志记录”——它与向 Web 服务器记录请求有关,而不是在程序中更通用地记录事件。

标签: python django logging


【解决方案1】:

这个数字就是响应内容的长度,也就是:发送的字节数。

这个输出基本上来自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)

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

log_request([code[, size]])

记录一个接受的(成功的)请求。 code 应指定与 回复。如果响应的大小可用,那么它应该是 作为大小参数传递。

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

另见:

【讨论】:

    猜你喜欢
    • 2016-02-21
    • 2011-07-25
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 2023-03-18
    • 2019-03-02
    • 1970-01-01
    • 2017-06-04
    相关资源
    最近更新 更多