Sentry Answers>Django>

Django: ValueError: unable to configure handle "loggers"

Django: ValueError: unable to configure handle "loggers"

David Y.

The Problem

You are trying to configure logging for your Django application, but keep getting the following error message:

Click to Copy
ValueError: Unable to configure handler 'loggers'

This is your logging configuration dictionary in settings.py:

Click to Copy
import os LOGGING = { "version": 1, "disable_existing_loggers": False, "root": { "handlers": ["console"], "level": "WARNING", }, "handlers": { "console": { "class": "logging.StreamHandler", }, "loggers": { "django": { "handlers": ["console"], "level": os.getenv("DJANGO_LOG_LEVEL", "INFO"), "propagate": False, }, }, }, }

What is the cause of this error and how do you fix it?

The Solution

The error is caused by a mistake in the structure of the logging dictionary. In the dictionary above, loggers is an element of handlers, but it should be a top-level element, per the Django documentation. A bare-bones LOGGING dictionary should be structured as follows:

Click to Copy
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { # add formatters here (optional) }, 'handlers': { # add handlers here }, 'loggers': { # add loggers here }, }

Here is a correctly indented version of the LOGGING dictionary:

Click to Copy
import os LOGGING = { "version": 1, "disable_existing_loggers": False, "root": { "handlers": ["console"], "level": "WARNING", }, "handlers": { "console": { "class": "logging.StreamHandler", }, }, "loggers": { "django": { "handlers": ["console"], "level": os.getenv("DJANGO_LOG_LEVEL", "INFO"), "propagate": False, }, }, }
  • Syntax.fmListen to the Syntax Podcast (opens in a new tab)
  • Community SeriesIdentify, Trace, and Fix Endpoint Regression Issues (opens in a new tab)
  • ResourcesBackend Error Monitoring 101 (opens in a new tab)
  • Syntax.fm logo
    Listen to the Syntax Podcast (opens in a new tab)

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “not bad” by 4 million developers and more than 150,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.