Periodic Django Logs in Terminal - python

I am new to Django and this question may seem to be easy. In the terminal where "python manage.py runserver" is executed, the following logs periodically appear.
[30/Sep/2015 02:36:02] "GET /messages/check/?_=1443574208652 HTTP/1.1" 200 1
[30/Sep/2015 02:36:08] "GET /notifications/check/?_=1443574208653 HTTP/1.1" 200 1
[30/Sep/2015 02:36:08] "GET /feeds/update/?first_feed=13&last_feed=6&feed_source=all&_=1443574208655 HTTP/1.1" 200 173
[30/Sep/2015 02:36:08] "GET /feeds/check/?last_feed=13&feed_source=all&_=1443574208654 HTTP/1.1" 200 1
[30/Sep/2015 02:36:39] "GET /notifications/check/?_=1443574208656 HTTP/1.1" 200 1
[30/Sep/2015 02:36:39] "GET /feeds/check/?last_feed=13&feed_source=all&_=1443574208658 HTTP/1.1" 200 1
[30/Sep/2015 02:36:39] "GET /feeds/update/?first_feed=13&last_feed=6&feed_source=all&_=1443574208657 HTTP/1.1" 200 173
[30/Sep/2015 02:37:03] "GET /messages/check/?_=1443574208659 HTTP/1.1" 200 1
My Django virtual environment is as follows:
bleach==1.4
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.6.5
gunicorn==19.3.0
html5lib==0.9999999
Markdown==2.4.1
Pillow==2.4.0
psycopg2==2.6.1
python-decouple==2.2
six==1.9.0
South==0.8.4
static3==0.6.1
Unipath==1.0
Questions are:
Why does the logs periodically appear? I guess there is a background task running.But Celery package is not used here.
How to configure the logs, for example, displaying one more logs such as:
/followers/check/?_=9896886900907 HTTP/1.1
What do "?_" and the long string of numbers stand for? I can understand the "?first_feed=13" means the querying parameter in Django request object.
GET /notifications/check/?_=1443574208656

When Django is run in development mode (with runserver) it prints a line for all HTTP requests received to the console.
All of them are coming from the outside, browsers, feed readers...
The parameters you are wondering about are GET query parameters. The ? is the delimiter so, _ is the key of the argument.
In development mode the logging is defined by default. If you want to have logging on your production system or more logging, read https://docs.djangoproject.com/en/1.8/topics/logging/ .

Related

How to add response time in gunicorn access log

I have a gunicorn *config.py and need to add response time to gunicorn access log:
Here's what I have:
...
accesslog = some_path/filename
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
...
gunicorn version 19.7.1
Some more details:
*config.py didn't contain the seting access_log_format before, and I thought adding it might help, but even after I added and restarted the process, the access log contains the same parameters as before:
<ip> - - [16/Aug/2020:14:11:35 XDT] "POST /ws/v1/sessions?userId=<username> HTTP/1.1" 200 537 "-" "python-requests/2.22.0"
<ip> - - [16/Aug/2020:14:11:56 XDT] "DELETE /ws/v1/sessions HTTP/1.1" 200 139 "-" "python-requests/2.22.0"
<ip> - - [17/Aug/2020:04:05:40 XDT] "GET /ws/v1/data-specs HTTP/1.1" 200 35097 "-" "python-requests/2.22.0"
<ip> - - [17/Aug/2020:09:30:31 XDT] "GET /ws/v1/data-specs HTTP/1.1" 200 35097 "-" "python-requests/2.22.0"
I am new to python, gunicorn and web apis. I am unable to figure out how to add response time to the log. What am I doing wrong here? Please help.
From the documentation (https://docs.gunicorn.org/en/stable/settings.html#access-log-format)
The corresponding value for response time miliseconds is %(D)s

Form not appearing using Django/HTML/Python [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am new to Django and web development. I don't know how to describe my problem. No idea what info to provide. I need some hints to debug.
I have two virtual machines. On one machine, I built my Django project, installed the package, and run it on apache2.
On the other machine, I run python manage.py runserver 0.0.0.0:8000 from the source codes.
Browsing the same page, the web page on machine 1 is OK.
But nearly every form disappeared on machine 2.
Checked the source of the two pages, they are the same.
The output on machine 2 seems OK too:
[17/Mar/2016 19:36:40] "GET /myapp/dashboard/reports/new HTTP/1.1" 302 0
[17/Mar/2016 19:36:40] "GET /myapp/dashboard/reports/0 HTTP/1.1" 200 43321
[17/Mar/2016 19:36:40] "GET /myapp/static/dist/css/vendor.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/main.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/dashboard.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/query.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/report.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/dist/js/commons.bundle.js?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/dist/js/analytics.bundle.js?v=v1.71 HTTP/1.1" 304 0
UPDATE
ERROR:
Uncaught TypeError: $(...).daterangepicker is not a functiont.exports.n.View.extend.initialize # analytics.bundle.js?v=v1.71:2e.View # commons.bundle.js?v=v1.71:56n # commons.bundle.js?v=v1.71:56t.exports.n.View.extend.initialize # analytics.bundle.js?v=v1.71:1e.View # commons.bundle.js?v=v1.71:56n # commons.bundle.js?v=v1.71:56(anonymous function) # analytics.bundle.js?v=v1.71:1c # commons.bundle.js?v=v1.71:24h.fireWith # commons.bundle.js?v=v1.71:24vt.extend.ready # commons.bundle.js?v=v1.71:24h # commons.bundle.js?v=v1.71:14
UPDATE
Solved this problem. see the error above. It failed to import some js files, and then the page not shown.
If they're each using separate copies of the database server, it may be that database migrations have not been run yet on machine 2.

Error getting started with cloud endpoints on GAE

I'm just getting started with cloud endpoints by following the tutorial from
here.
Even when i copy paste the code exactly, I'm unable to look at the custom endpoin methods. When I run the project and type
http://localhost:8080/_ah/api/explorer
I get redirected to a blank api-explorer page. Here are the logs from the App Engine Launcher
INFO 2015-09-22 20:45:52,114 devappserver2.py:763] Skipping SDK update check.
INFO 2015-09-22 20:45:52,661 api_server.py:205] Starting API server at: http://localhost:53371
INFO 2015-09-22 20:45:52,676 dispatcher.py:197] Starting module "default" running at: http://localhost:8080`
INFO 2015-09-22 20:45:52,676 admin_server.py:118] Starting admin server at: http://localhost:8000
INFO 2015-09-22 20:46:08,792 module.py:808] default: "GET /_ah/api/explorer HTTP/1.1" 302 -
INFO 2015-09-22 20:46:12,805 module.py:808] default: "GET /_ah/api/explorer HTTP/1.1" 302 -
INFO 2015-09-22 20:46:17,711 module.py:808] default: "GET /_ah/api/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.z0-pPDgHPQw.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCO4-ZDXf1JrE4AXDItAeFdjXKLW8w HTTP/1.1" 200 7690
The app.yaml and python files are exactly as described in the tutorial.
Can someone please tell me what exactly is going on and how to fix it.

Redirect BaseHTTPServer stdout to logging

I wrote a quick webserver using BaseHTTPServer, and it's working nicely, so now I'm trying to implement logging, and I noticed, hey, seems like BaseHTTPServer already has some logging information that it spits out to the stdout, is there a way to implement my logging to also include this stdout.
i.e. Have logging record all information from the stdout.
Note: I am not explicitly printing anything to the console window, when a GET request is made, BaseHTTPServer handles printing this to the console.
Example:
127.0.0.1 - - [02/May/2014 20:51:52] "GET /postTest.html HTTP/1.1" 200 -
127.0.0.1 - - [02/May/2014 20:51:52] "GET /assets/foundation.js HTTP/1.1" 200 -
127.0.0.1 - - [02/May/2014 20:51:52] "GET /assets/bootstrap.css HTTP/1.1" 200 -
127.0.0.1 - - [02/May/2014 20:51:57] "GET /index.html HTTP/1.1" 200 -
127.0.0.1 - - [02/May/2014 20:51:57] "GET /assets/foundation.js HTTP/1.1" 200 -
127.0.0.1 - - [02/May/2014 20:51:57] "GET /assets/bootstrap.css HTTP/1.1" 200 -
According to the BaseHTTPServer documentation, you can override the log_message method to do this. By default, it just writes to stderr, but you can make it write to your logger instead (or have it write to both).

Degguging bottle does not work

I cannot debug bottle. I have 500 errors in dev. I am using the latest bottle wit the debug=True flag.
if __name__ == "__main__":
# Interactive mode
run(host='localhost', port=8049,debug=True)
This is what I get.....
Bottle v0.11.rc1 server starting up (using WSGIRefServer())...
Listening on http://localhost:8049/
Hit Ctrl-C to quit.
localhost - - [30/Sep/2012 18:59:13] "POST /bidder/ HTTP/1.1" 500 1407
localhost - - [30/Sep/2012 18:59:14] "POST /bidder/ HTTP/1.1" 500 1407
localhost - - [30/Sep/2012 18:59:14] "POST /bidder/ HTTP/1.1" 500 1407
localhost - - [30/Sep/2012 18:59:15] "POST /bidder/ HTTP/1.1" 500 1407
localhost - - [30/Sep/2012 18:59:15] "POST /bidder/ HTTP/1.1" 500 1407
I don't mind the 500 as long I can find out why?
The debug=False keyword parameter in the run() function is only available in the current development version; the current 0.10.x code itself ignores doesn't yet support it.
Instead, use the debug() function instead:
if __name__ == "__main__":
# Interactive mode
run(host='localhost', port=8049)
debug(True)
or run with the --debug command-line flag.
You may have to import the debug function from bottle if you haven't done so already. The tutorial explains debug mode in more detail.

Categories