Skip to main content

Log everything from your DRF view

Project description

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
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_rest_api_logger-0.4.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file django_rest_api_logger-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: django_rest_api_logger-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for django_rest_api_logger-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1447fd761dc4acfd6e86a1f774502ce0b44786b2b714e4618dd811c7b36c82c1
MD5 a296dc5f8ce6b126745971a59a35fd06
BLAKE2b-256 9f1b749892449889ba5f084cd2c994ff2183991427f3d1d41995cf2b4136f010

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page