python - django runserver 的这个特定日志输出来自哪里

标签 python django logging

我正在学习如何在 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

最佳答案

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

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

Logs an accepted (successful) request. code should specify the numeric HTTP code associated with the response. If a size of the response is available, then it should be passed as the size parameter.

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

另见:

关于python - django runserver 的这个特定日志输出来自哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18634193/

相关文章:

javascript - 某些方法如何知道提前进行论证?

python - 通过代理创建的Django用户无法登录

python - 选择相关 选定相关

mysql - 在django中查看mysql日志

node.js - 如何使用 json-masker 对包含 "-"的字段屏蔽 json?

python - 如何根据位置替换字符串中多个相同的字符?

python - 在 beautifulsoup4 中具有子元素的标签内提取文本节点

Python 日志记录 - 将日期设置为文件名

Python HTTP 错误 429 与 urllib2

asp.net - 通过 smtppickupfolder 使用 MS 企业库日志记录应用程序 block 发送电子邮件?