9

I am learning about logging in python, so I am trying to find out where in the source code is the portion to format the line when you get this specific output: "GET /dashboard/ HTTP/1.1" 200 249176? Also, what does 249176 mean?

I do not have a problem, and this question is to satisfy my curiosity.

I am really looking for the formatter for this logrecord. I also do not see what loghandler this is coming from (perhaps this is not comming from the logging module at all, and it is just a print command). I searched the source code and could not find where this is coming from, and would like to have a link to the source.

Here is what happens when I run my code.

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
Rafa Viotti
  • 9,998
  • 4
  • 42
  • 62
Trewq
  • 3,187
  • 6
  • 32
  • 50
  • Note: this is "logging for web servers" rather than "logging in Python" - it relates to logging requests to a web server, rather than more generalised logging of events in a program. – Vinay Sajip Sep 05 '13 at 18:54

1 Answers1

8

This number is the response content length, in other words: number of bytes sent.

This output basically comes from wsgiref's simple_server (and it is based on BaseHTTPServer) that is django's class WSGIRequestHandler as the follows (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() function is actually logging the code and content size under the hood:

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.

If you are interested, take a look at BaseHTTPServer pypy realization: https://bitbucket.org/pypy/pypy/src/9d88b4875d6e/lib-python/2.7/BaseHTTPServer.py

See also:

caot
  • 3,066
  • 35
  • 37
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195