0
0
Djangoframework~30 mins

Monitoring and error tracking in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Monitoring and Error Tracking in Django
📖 Scenario: You are building a simple Django web application. To keep your app healthy and catch problems early, you want to add basic monitoring and error tracking.This will help you see when errors happen and understand your app's status.
🎯 Goal: Set up a basic error logging system in Django that records errors to a file and configure a simple health check view to monitor app status.
📋 What You'll Learn
Create a Django settings dictionary with logging configuration
Add a log file handler to capture errors
Write a health check view that returns HTTP 200 with a simple message
Print the log file path to confirm setup
💡 Why This Matters
🌍 Real World
Monitoring and error tracking help keep web applications reliable by alerting developers to problems quickly and providing data to fix issues.
💼 Career
Understanding how to configure logging and health checks is essential for DevOps roles and backend developers to maintain production systems.
Progress0 / 4 steps
1
Create basic logging configuration
Create a dictionary called LOGGING in Django settings with a version key set to 1 and an empty handlers dictionary.
Django
Need a hint?

Start with a dictionary named LOGGING that has keys 'version' and 'handlers'.

2
Add a file handler for error logs
Add a file handler inside LOGGING['handlers'] with level set to 'ERROR', class set to 'logging.FileHandler', and filename set to 'django_error.log'.
Django
Need a hint?

Inside handlers, add a file handler dictionary with the specified keys and values.

3
Configure loggers to use the file handler
Add a loggers dictionary to LOGGING with a 'django' logger that uses the 'file' handler and has level set to 'ERROR'.
Django
Need a hint?

Inside LOGGING, add a loggers dictionary with a 'django' key that uses the 'file' handler.

4
Create a health check view and print log file path
Create a Django view function called health_check that returns an HttpResponse with text 'OK'. Then, print the string 'Log file: django_error.log'.
Django
Need a hint?

Define a function health_check that returns HttpResponse('OK'). Then print the log file path string.