How can I log the requests that my django server makes? - django

I know that I can use logging to log all the requests that my django server gets. However I would like to log the requests along with headers and body that my django server makes to other servers. How can I access this info?

What type of logs do you really want?
1 - in development mode, you can get the request as .txt using: python manage.py runserver > logs.txt - source: stackoverflow
2 - The Apache2 webserver provides two important logs: error.log or access.log. If you are using debian/ubuntu, you can get it in?
/var/log/apache2/error.log or access.log

Related

Axios with django server on localhost

Trying to access django server on localhost from my react native app. All I get is Network Error, which doesn't say much. Tried changing info.plist file as suggested in other answers on stack, tried changing firewall settings and so on.
The thing that worked and solved all my problems was changing the url on axios to my local ip and running django server with command: python manage.py runserver 0.0.0.0 which to my understanding will accept any connection to the server.

502 Bad Gateway: nginx - Log: upstream prematurely closed connection while reading... [Django 2.1 | gunicorn 19.7.1 | Google Cloud Platform]

I'm new in a company that have this project on Google Cloud PLatform, that I've never used. In my first day I've got this 502 Bad Gateway error. Lookin the log on the Google Cloud Platform I've got the following:
[error] 33#33: *285 upstream prematurely closed connection while reading response header from upstream, client: 172.217.172.212, server: , request: "POST /product/fast_appraisal/result/ HTTP/1.1", upstream: "http://172.17.0.1:8080/product/fast_appraisal/result/", host: "avalieidjango.appspot.com", referrer: "https://avalieidjango.appspot.com/product/fast_appraisal/search/"
I've tried to edit the app.yaml adding --timeout and --graceful-timeout parameters to it like the following:
# [START runtime]
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT mysite.wsgi --timeout=90 --graceful-timeout=10
beta_settings:
cloud_sql_instances: avalieidjango:southamerica-east1:avaliei
runtime_config:
python_version: 3
handlers:
- url: /.*
script: manage.py
secure: always
redirect_http_response_code: 301
# [END runtime]
In the settings.py file DEBUG variable is setted to False
Looking for answers on the internet I found a few cases, but no one looks like mine exactly.
Locally I'm running the project on Windows 7, so the error only occurs when I deploy it to GCP. I'm new on GCP and gunicorn.
Edit
After these days I've passed through a lot of forums, and added a few new configurations to my app.yaml trying to work with threads and workers to solve the question.
The entrypoint line looks like this:
entrypoint: gunicorn -b :$PORT --worker-class=gevent --worker-connections=1000 --workers=3 mysite.wsgi --timeout 90
This project consists in search a Postgres database on GCP gathering information about properties and running an AI to show some predictions about its values.
I've tried threads and process, but even with just my requests the application is too slow, even a simple page take some time to render.
Local tests run better, but in production it isn't working at all.
The AI wasn't developed for me and it uses a large joblib file.
The project doesn't use containers like Docker. Maybe it could help in some way if I "dockerize" the project?
I've stoped seeing this error changing CONN_MAX_AGE value to None, which keeps the database connetion time undefined. However this may cause some security issues that must be evaluated before deploy your application. If you change it, stay tuned on Google Cloud Logs looking for strange connection attempts.

django digital ocean gunicorn logfiles creating a 502

I am going nuts here, I am trying to get django logging to work, which led me to need to check the gunicorn logs which I found were not setup and when i try to set them up via the config file it throws a 502 and I don't know how to track it down...
according to this... https://www.digitalocean.com/community/tutorials/how-to-use-the-django-one-click-install-image
the config file on the DO deployment is at... /etc/gunicorn.d/gunicorn.py
now when I go to that file and add a line like this as per the gunicorn docs tell me to do in the config file, and then I restart gunicorn it throws a 502 at me...
"""gunicorn WSGI server configuration."""
from multiprocessing import cpu_count
from os import environ
def max_workers():
return cpu_count() * 2 + 1
max_requests = 1000
worker_class = 'gevent'
workers = max_workers()
#my added config
errorlog = '/var/log/gunicorn/error.log'
Interesting to note is that when I srestart gunicorn with
sudo service gunicorn restart
it goes smoothly the first time and then if I try to restart it again it gives me this...
stop: Unknown instance:
gunicorn start/running, process 30943
I have tried contacting digital ocean about this and so far they have not been helpful, any ideas of where to go next?
This was cause by the permissions of the log files for some reason. Through some more testing I have found that the log files need to be already in place, and their permissions need to be set to no less than 666.
I have no idea why they need to be this high...

django + nginx + fastcgi - how to keep webserver up?

I'm running nginx as a reverse proxy to fastcgi for django. I'm using the following command (will switch later to using sockets to avoid tcp overhead):
python /home/ubuntu/system/sites/manage.py runfcgi host=127.0.0.1 port=8080 pidfile=/home/ubuntu/system/logs/fastcgi.pid maxspare=2
I'm not too familiar with django, but how do I reload my project after making changes? I've made some changes to my views.py file however the website isn't updating with those changes so I assume there is some caching going on.

Django & Apache: How to debug on Testing server

I am trying to debug an issue that happens on our testing server. So how do I make it so that I can access our testing server when I start Django by typing:
python manage.py runserver
?
Does it have to pass through Apache? If so, I need to configure Apache somehow but I am not using mod_wsgi and so, don't know how to do this.
Thanks! :)
the test server runs its own web server. the defaul options starts a server on
http://127.0.0.1:8000/, which you can then open in your browser
you can specify an optional ip address/server using
manage.py runserver ip:port
using ip 0.0.0.0 for all network interfaces