Django not logging stacktraces for 500 errors

My app isn’t working for some reason (django 5.0.7). All I see in the logs are lines like this with no stacktrace or error message:

[ERROR 2024-08-07 13:41:41,594 django.request] Internal Server Error: /admin

Here’s my logging config:

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "file": {
            "level": "INFO",
            "class": "core.utils.log.GroupWriteRotatingFileHandler",
            "filename": "/var/log/django/django.log",
            "formatter": "verbose",
            "maxBytes": 1024 * 1024 * 50,  # 50 MB
            "backupCount": 5,  # Keep up to 5 backups
        },
    },
    "root": {
        "handlers": ["file"],
        "level": "INFO",
    },
    "loggers": {
        "django": {
            "handlers": ["file"],
            "level": "INFO",
            "propagate": True,
        },
    },
    "formatters": {
        "verbose": {
            "format": "[{levelname} {asctime} {name}] {message}",
            "style": "{",
        },
    },
}

How can I enable logged stacktraces for 500 errors with debug = False? If I set debug=True I can use the admin so I can’t even get a stacktrace that way :frowning:

The stack trace information is passed through to the formatter under the keys exc_info and exc_text.

If you look at the default handler for these (the one sending the stack trace through email, AdminEmailHandler), you can see that it actually ignores what’s supplied in the log record and generates its own.

You may want to do that here - you may find it better to write your own handler to format the output rather than just relying upon what the system would provide by including exc_text in your message.

Hmm it’s strange. I added one of those (exc_info IIRC), but it just logged ‘None’. And also, since disabling debug mode the site now works… I’ll try deleting all the *.pyc files and see if that breaks it again. Thanks, I didn’t know about exc_text.

try StreamHandler.

"loggers": {
        "django": {
            # "handlers": ["file"],
            "class": "logging.StreamHandler",
            "level": "INFO",
        },
    },