Skip to main content

DRF Request logger

PyPi version

A spinoff of the drf-tracking to forward the logging to the standard output instead of saving it in the database

Installation

pip install drf-tracking-logger

Usage

To use a specific logger name, set an environment variable TRACKING LOGGER.

The package provides a mixin LoggingMixin which you can include to your class based views to log the requests.

Example,

from rest_framework.generics import GenericAPIView
from rest_framework.mixins import ListModelMixin
from drf_tracking_logger.mixins import LoggingMixin

class AnyRandomView(LoggingMixin, ListModelMixin, GenericAPIView):
    ...

Options

  • 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.

Logging Overview

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 User if authenticated, None if not Foreign Key
requested_at Date-time that the request was made DateTimeField
response_ms Number of milliseconds spent in view code PositiveIntegerField
path Target URI of the request, e.g., "/api/" CharField
view Target VIEW of the request, e.g., "views.api.ApiView" CharField
view_method Target METHOD of the VIEW of the request, e.g., "get" CharField
remote_addr IP address where the request originated (X_FORWARDED_FOR if available, REMOTE_ADDR if not), e.g., "127.0.0.1" GenericIPAddressField
host Originating host of the request, e.g., "example.com" URLField
method HTTP method, e.g., "GET" CharField
query_params Dictionary of request query parameters, as text TextField
data Dictionary of POST data (JSON or form), as text TextField
response JSON response data. This will be skipped for GET requests TextField
status_code HTTP status code, e.g., 200 or 404 PositiveIntegerField

Metadata

Release files for drf-tracking-logger 1.9.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for drf-tracking-logger 1.9.6
File Interpreter ABI Platform Actions
drf_tracking_logger-1.9.6-py3-none-any.whl Python 3 none any Details for drf_tracking_logger-1.9.6-py3-none-any.whl

Release files / drf_tracking_logger-1.9.6-py3-none-any.whl

Download URL drf_tracking_logger-1.9.6-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a5c004a57fe23e13b6b6e969b45ed03da138309ad95927bda937c8fb7d1e245
BLAKE2b-256 checksum
How to use checksums
205b4238a54b845373ff7c86419d702a2e36205dfbab1f723fd00f061ec6153b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Security for drf-tracking-logger 1.9.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page