3

How can I log the requests and responses that the Django server handles?

I have a Django server application has tables and relations. Many tables are exposed through several API endpoints. There are also several custom functions that take GET/POST requests with params and run a function in python and return a result.

As the server admin, I would like to log all the incoming requests and the outgoing responses for each of these requests. It is essential to me that I capture the GET/POST params made with each requests and the data that is sent out with each response. What would be the best way for me to implement this?

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125

2 Answers2

1

I would suggest you DON'T do this through Django, all you're going to do is add to the request work load. You're going to make your application slower, all so you can have it in "one place", remember, "the right tool for the job".

I highly suggest you log to a standard logger file/syslog, and then use something like GrayLog/Loggly/Splunk/Logstash/etc. -- you're going to thank me in the long run, you're not going to grind your Django server and/or DB to the ground.

If you think I'm kidding, think of this: you're more likely going to put this in a middleware right? BEFORE auth, right? If I wanted to make your life a living hell all I have to do is while true; do curl https://yourdomain.com/doesnt-need-to-exist &; done i'm going to fill your DB up in a couple of days, not to mention degrade your service as a whole. Do everyone a favor and don't use the db, specially a prod db to store logs

Javier Buzzi
  • 6,296
  • 36
  • 50
0

django-wiretap is a package that stores the requests and responses in the database via models.

Javier Buzzi
  • 6,296
  • 36
  • 50
anush0247
  • 91
  • 1
  • 12