Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where does this specific log output from django runserver come from

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
like image 916
Trewq Avatar asked Sep 05 '13 10:09

Trewq


People also ask

Where are Django logs stored?

The Django One-Click application employs Gunicorn and Upstart. Application level logging can be found in /var/log/upstart/gunicorn. log By default, Gunicorn logs to stderr and Upstart will collect output to stderr/stdout in /var/log/upstart/$JOB_NAME.

What does Runserver do in Django?

The runserver command is a built-in subcommand of Django's manage.py file that will start up a development server for this specific Django project.

When Django developers run a Runserver command line what does it start?

The very first thing we learn while learning about Django is “How to start a server?”. For this you have to go to the project directory and the type the command “python manage.py runserver” and the server starts listening at “127.0. 0.1:8000” a.k.a “localhost:8000”, as simple as that.


1 Answers

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:

  • What's the meaning of the default output of manage.py runserver?
like image 150
alecxe Avatar answered Sep 22 '22 12:09

alecxe