Skip to content

Logging Configuration

Professor Colin Turner edited this page Dec 27, 2025 · 2 revisions

Logging Configuration

WAM can be persuaded to log to console, file, at various log levels.

Here's an example configuration for local_settings.py that enables debug level logging on the console, but logs management commands into django.log. You should consider more conservative settings in production, and a rotating log file.

import os
from django.utils.log import DEFAULT_LOGGING

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    'formatters': {
        'default': {
            # exact format is not important, this is the minimum information
            'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
        },
        'django.server': DEFAULT_LOGGING['formatters']['django.server'],
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
            'formatter': 'default',
        },
        "file": {
            "class": "logging.FileHandler",
            "formatter": "default",
            "filename": "./django.log",
        }
        "mail_admins": {
            "level": "ERROR",
            "class": "django.util.log.AdminEmailHandler",
            "include_html": True,
        },
    },
    "root": {
        "handlers": ["console", "mail_admins"],
        "level": "DEBUG",
        'formatter': 'default',
    },
    "loggers": {
        "django": {
            "handlers": ["console", "mail_admins"],
            "level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
            "propagate": False,
        },
        "loads.management": {
            "handlers": ["file", "mail_admins"],
            "level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
            "propagate": False,
        },
    },
}

Clone this wiki locally