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
- Django
The package is available on PyPI:
pip install django-rest-api-logger
IMPORTANT: Don't forget to put it in the first base class
class ProductListAPI(APILoggingMixin, OtherMixinsOrClass):
...
Put these variables in your django settings file
-
# 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"
-
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 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"
-
# 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