Log DRF requests on specified logger
DRF Request logger
A spinoff of the drf-tracking to forward the logging to the standard output instead of saving it in the database
pip install drf-tracking-logger
To use a specific logger name, set an environment variable
The package provides a mixin
LoggingMixin which you can include to your class based views to log the requests.
from rest_framework.generics import GenericAPIView from rest_framework.mixins import ListModelMixin from drf_tracking_logger.mixins import LoggingMixin class AnyRandomView(LoggingMixin, ListModelMixin, GenericAPIView): ...
logging_methods: This attribute can used to strip down the request methods which needs to be logged. It logs all the methods by default.
should_log: This method can be used to customize the logic to determine the logging.
handle_log: You can override this method to change the logging behavior. It sends the log to the configured logger by default.
sensitive_fields: By default, any key name which has any of
'key', 'secret', 'password', 'signature'in its name, will get its value hidden. But you can extend this list by adding more using this attribute.
You'll get these attributes for every request/response cycle to a view that uses the mixin:
|Model field name||Description||Model field type|
||User if authenticated, None if not||Foreign Key|
||Date-time that the request was made||DateTimeField|
||Number of milliseconds spent in view code||PositiveIntegerField|
||Target URI of the request, e.g.,
||Target VIEW of the request, e.g.,
||Target METHOD of the VIEW of the request, e.g.,
||IP address where the request originated (X_FORWARDED_FOR if available, REMOTE_ADDR if not), e.g.,
||Originating host of the request, e.g.,
||HTTP method, e.g.,
||Dictionary of request query parameters, as text||TextField|
||Dictionary of POST data (JSON or form), as text||TextField|
||JSON response data. This will be skipped for GET requests||TextField|
||HTTP status code, e.g.,
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for drf_tracking_logger-1.9.6-py3-none-any.whl