Skip to main content

Django REST API Logger

Mixin which logs all needed data from API

Just import APILoggingMixin and put it in first base class of your API and it'll do the rest

Requirements

  • Django

Installation

The package is available on PyPI:

pip install django-rest-api-logger

How to use

IMPORTANT: Don't forget to put it in the first base class

class ProductListAPI(APILoggingMixin, OtherMixinsOrClass):
    ...

Modes

Put these variables in your django settings file

  • Native Logger
    # file ------> Writes logs to file 
    # console ---> Prints logs in console
    DRF_LOGGER_HANDLER = ["file", "console"]
    
    # Log file directory
    # Make sure directory exists  
    DRF_LOGGER_FILE = "/tmp/custom_logger.log"
    
  • Elasticsearch
    DRF_LOGGER_ELASTICSEARCH_ENABLED = True
    
    # Elasticsearch Hosts
    DRF_LOGGER_ELASTICSEARCH_HOSTS = ["localhost:9200"]
    
    # Elasticsearch Index
    DRF_LOGGER_ELASTICSEARCH_INDEX = "django_rest_api_logger"
    
    # Elasticsearch Auth
    DRF_LOGGER_ELASTICSEARCH_AUTH = ('user', 'secret') # Or None
    
    # Elasticsearch SSL
    DRF_LOGGER_ELASTICSEARCH_SSL = False
    
  • Mongo Log
    # Mongo Host
    DRF_LOGGER_MONGO_HOST = "mongodb://username:password@localhost:27017/"
    
    # Mongo Attempting Connection Timeout:
    DRF_LOGGER_MONGO_TIMEOUT_MS = 10
    
    # Log db
    DRF_LOGGER_MONGO_LOG_DB = "log"
    
    # Log collection
    DRF_LOGGER_MONGO_LOG_COLLECTION = "logs"
    
  • Custom
    # If DRF_LOGGER_CUSTOM_HANDLER is set to false then aboves modes won't work
    # You have to override `handle_log` function in order to implement your own handler
    DRF_LOGGER_CUSTOM_HANDLER = False
    

Metadata

Release files for django-rest-api-logger 0.4.1

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 django-rest-api-logger 0.4.1
File Interpreter ABI Platform
django_rest_api_logger-0.4.1-py3-none-any.whl Python 3 none any Details

Release files / django_rest_api_logger-0.4.1-py3-none-any.whl

Download URL django_rest_api_logger-0.4.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1447fd761dc4acfd6e86a1f774502ce0b44786b2b714e4618dd811c7b36c82c1
BLAKE2b-256 checksum
How to use checksums
9f1b749892449889ba5f084cd2c994ff2183991427f3d1d41995cf2b4136f010
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.1 CPython/3.8.3

Security for django-rest-api-logger 0.4.1

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