Django Logging — A Weapon for Debuggers

Deepen Saha
2 min readSep 8, 2020

--

Programmer Debugging Code
Designed by stories / Freepik

Django — A Framework used for creating python based web applications

Logging — In the simplest way printing out data into a file or console (terminal) making it easier for developers to trace back the source of errors.

I have been a python developer for quite some time now and have had a very bad experience to go through Django documentation.

As developers our weapon of choice for any kind of bugs is logs. While Django has an excellent logging mechanism, the documentation is rather confusing. Here’s a small article on understanding logging in Django and how to configure it for your web application.

4 Parts to Django Logging Configuration

  1. Loggers — A named bucket for log records with log levels(Debug, Info, Warning, Error, Critical).
  2. Handlers — Defines the behaviour of your logger with some log levels.
  3. Filters — A mechanism to remove the unwanted logger records.
  4. Formatters — A mechanism to display log records in a certain way.

Using Logging in your Code

Logging Configuration

Django logs can be configured using the Django settings file. I have added a sample logging configuration for Django.

List of Log Record Formatting Attributes — View all Attributes

Full Example with Configuration and Usage

Furthermore, custom filters can be added, predefined Django loggers can also be used. for more customizations refer : Django Logging Documentation

--

--

Deepen Saha
Deepen Saha

Written by Deepen Saha

Full Stack Developer | System Architect | Product Developer | Finance Enthusiast | deepensaha.com

No responses yet