Basic Logging Configuration
A snippet showing how to configure basic logging in Django.
# settings.py
import os
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {"format": "[{levelname}] {message}", "style": "{"},
},
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "simple"},
},
"root": {
"handlers": ["console"],
"level": os.environ.get("DJANGO_LOG_LEVEL", "INFO"),
},
}
Explanation:
-
rootcaptures logs not handled by specific loggers; set a sane default level and handler. - All logs go to console with a simple format.
- Root level can be controlled via DJANGO_LOG_LEVEL env var (e.g., DEBUG/INFO/WARNING).
- Category Logging
- Total Views 534
- Last Modified 19 May, 2026
- Tags #logging #config #basics #settings
Previous snippet
Simple Rate Limiter (Cache Based)
Next snippet