# Django not logging stacktraces for 500 errors

**URL:** <https://forum.djangoproject.com/t/django-not-logging-stacktraces-for-500-errors/33637>\
**Category:** Mystery Errors\
**Created:** [August 7, 2024, 2:01pm UTC](https://forum.djangoproject.com/t/django-not-logging-stacktraces-for-500-errors/33637 "2024-08-07T14:01:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![billyt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/billyt/32/22715_2.png) [@billyt](https://forum.djangoproject.com/u/billyt)\
**Post date:** [August 7, 2024, 2:01pm UTC](https://forum.djangoproject.com/t/django-not-logging-stacktraces-for-500-errors/33637/1 "2024-08-07T14:01:39Z")

</div>

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:

```auto
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 ☹

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 7, 2024, 6:01pm UTC](https://forum.djangoproject.com/t/django-not-logging-stacktraces-for-500-errors/33637/2 "2024-08-07T18:01:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![billyt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/billyt/32/22715_2.png) [@billyt](https://forum.djangoproject.com/u/billyt)\
**Post date:** [August 7, 2024, 6:29pm UTC](https://forum.djangoproject.com/t/django-not-logging-stacktraces-for-500-errors/33637/3 "2024-08-07T18:29:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![white-seolpyo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/white-seolpyo/32/22386_2.png) [@white-seolpyo](https://forum.djangoproject.com/u/white-seolpyo)\
**Post date:** [August 8, 2024, 1:16am UTC](https://forum.djangoproject.com/t/django-not-logging-stacktraces-for-500-errors/33637/4 "2024-08-08T01:16:41Z")

</div>

try StreamHandler.

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