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

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

Uploaded Python 3

Supported by

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