Grant Zukel
Grant Zukel

Reputation: 1181

How to do a Customer Logger for Django to Capture Response and Request

I'm looking into differen't ways to capture the response object, request object, and performance in Django to create a custom json elk logger that will build audit logs.

I'm not sure what approach is best to take here. I was looking at custom middleware but I've never done that.

I tried to look up if it was possible to use a decorator to do this but doesn't seem like it.

Also, I use the django rest framework so I also have to figure out how to integrate the middleware if thats the route or whatever solution to DRF as well.

Looking for suggestions.

Upvotes: 0

Views: 553

Answers (1)

Denis Sukhoverkhov
Denis Sukhoverkhov

Reputation: 90

If you use DRF, i advice you pckage - drf-tracking. Just add mixin LoggingMixin to you class like this:

class ProbeView(LoggingMixin, APIView):
    ...

And after this, each qyery for this view wiil be logged in database. Example: enter image description here

Upvotes: 1

Related Questions