vishalanandl177 / DRF-API-Logger

An API Logger for your Django Rest Framework project.
https://github.com/vishalanandl177/DRF-API-Logger
Apache License 2.0
303 stars 57 forks source link

How add user_id for logging if user has authorization? #51

Closed shiloanton closed 2 years ago

shiloanton commented 2 years ago

It would be very convenient to log based on the user ID. But as far as I can see there is no such thing by default, maybe there are thoughts on how to do this?

vishalanandl177 commented 2 years ago

You can use logger signals for custom logs. There you can filter and log manually.

vishalanandl177 commented 2 years ago

You can also create a new middleware and extend the DRF API Logger middleware. Set this new middleware in settings. In this new middleware, you can override your function.

shiloanton commented 2 years ago

Yes, I understand, thanks, but even so it would be cool to add user_id logging for example as an option.

vishalanandl177 commented 2 years ago

Usually, we are not supposed to log any user's related information, for example, user auth token, password, or personal information. If you want to log user_id as well, better send it in headers (value should be encrypted).

I strongly recommend not logging users' related information.