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:
  • root captures 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 533
  • Last Modified 19 May, 2026
  • Tags #logging #config #basics #settings
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.