Sentry Answers>Django>

Django: ValueError: unable to configure handle "loggers"

Django: ValueError: unable to configure handle "loggers"

David Y.

The ProblemJump To Solution

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, }, }, }
  • Community SeriesIdentify, Trace, and Fix Endpoint Regression Issues
  • ResourcesBackend Error Monitoring 101
  • Syntax.fm logo
    Listen to the Syntax Podcast

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

    SEE EPISODES

Loved by over 4 million developers and more than 90,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.

© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.