Django Logging — A Weapon for Debuggers
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
- Loggers — A named bucket for log records with log levels(Debug, Info, Warning, Error, Critical).
- Handlers — Defines the behaviour of your logger with some log levels.
- Filters — A mechanism to remove the unwanted logger records.
- 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