The Missing How-to for Django Logging

If you are working on Django, you might have faced difficulty in configuring logging with a dict in settings.py file. You go about writing your dict but your values are not valued and have no effect.

Image for logging config done right

There is a very simple solution for this problem and that is properly overriding the logging config so that whatever Django has already configured is replaced with your own best in class(atleast for you) logging config.

To provide a wholesome example, The above config is using such awesome projects as colorlog(errors will be red and warnings will be yellow etc), django-log-request-id(append a unique string for a particular user to capture user-journey) and Azure sdk libs(to show how you can reduce some libs logging behaviour). The logs are also all going to console to make it more container friendly for modern deployments to something like Kubernetes.

Now you can add or remove the configs in the dict as you please without any side-effects from Django’s own log configs.

You might be using Celery also which will need additional configuration to be able to work. For that checkout my next article.