---
title: "Set up Django logging and keep the traceback of every 500 error"
description: "With DEBUG = False and no LOGGING, Django printed no 500 traceback. Here is the Django logging setup with LOGGING, the log levels, and how to send errors to LogBrew, tested on Django 6.1."
canonical: "https://logbrew.co/en/guides/django-logging"
last_updated: "2026-11-21"
---

# Set up Django logging and keep the traceback of every 500 error

With `DEBUG = False` and no `LOGGING`, Django printed no 500 traceback. Here is the Django logging setup with `LOGGING`, the log levels, and how to send errors to LogBrew, tested on Django 6.1.

Tested on November 21, 2026 with Python 3.13.5, Django 6.1.3, logbrew-sdk 0.1.29, logbrew-django 0.1.12, and logbrew CLI 0.1.96

By [Furkan Erday](https://github.com/furkanerday). Furkan Erday is the founder of LogBrew. He builds LogBrew with Claude Code and Codex every day.

Canonical: https://logbrew.co/en/guides/django-logging

## What Django prints with no `LOGGING`, and what LogBrew gets

| Event | Printed with no `LOGGING` | Issue or log in LogBrew |
| --- | --- | --- |
| `logger.debug()` | Dropped | Dropped at `INFO` |
| `logger.info()` | Dropped | `info` log |
| `logger.warning()` | Message only | `warning` log |
| `logger.exception()` | Message and traceback | Log with the exception |
| `ValueError` in a view | Access line only | Issue |
| `Http404` | Access line only | Span, no issue |

6 events in Django 6.1.3 with `DEBUG = False`, then the same with our `LOGGING` dict and logbrew-django 0.1.12.

## Configure Django logging

### See what Django prints with no LOGGING

Our app has 1 logger named `taproom` and 4 views. With `DEBUG = False` and no `LOGGING` setting, Django printed `warning` and higher as bare text and dropped `debug` and `info`. The 500 error printed only its access line, with no traceback.

```bash
import logging

from django.http import Http404, JsonResponse
from django.urls import path

logger = logging.getLogger("taproom")


class CardDeclined(Exception):
    pass


def pour(request, tap):
    logger.debug("keg pressure read")
    logger.info("tap %s opened", tap)
    logger.warning("keg below 10%")
    logger.error("keg empty")
    logger.critical("cooler offline")
    return JsonResponse({"tap": tap})


def keg(request, keg_id):
    raise ValueError(f"keg {keg_id} is empty")


def missing(request):
    raise Http404("no such tap")


def pay(request):
    try:
        raise CardDeclined("card declined")
    except CardDeclined:
        logger.exception("payment failed")
        return JsonResponse({"error": "card declined"}, status=402)


urlpatterns = [
    path("taps/<str:tap>/", pour),
    path("kegs/<int:keg_id>/", keg),
    path("missing/", missing),
    path("pay/", pay),
]
```

Output

```text
keg below 10%
keg empty
cooler offline
[21/Nov/2026 00:41:16] "GET /taps/ipa/ HTTP/1.1" 200 14
[21/Nov/2026 00:41:16] "GET /kegs/7/ HTTP/1.1" 500 145
[21/Nov/2026 00:41:16] "GET /missing/ HTTP/1.1" 404 179
payment failed
Traceback (most recent call last):
  File "urls.py", line 32, in pay
    raise CardDeclined("card declined")
urls.CardDeclined: card declined
[21/Nov/2026 00:41:16] "GET /pay/ HTTP/1.1" 402 26
```

### Add a LOGGING dict to settings.py

Send the root logger to the console, and keep `disable_existing_loggers` at `False` so that Django's own loggers stay on. Now `django.request` printed the 500 error with its traceback at `ERROR`, and the 404 at `WARNING`.

```bash
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "plain": {"format": "{levelname} {name} {message}", "style": "{"},
    },
    "handlers": {
        "console": {"class": "logging.StreamHandler", "formatter": "plain"},
    },
    "root": {
        "handlers": ["console"],
        "level": os.environ.get("LOG_LEVEL", "INFO"),
    },
}
```

Output

```text
INFO taproom tap ipa opened
WARNING taproom keg below 10%
ERROR taproom keg empty
CRITICAL taproom cooler offline
[21/Nov/2026 00:41:20] "GET /taps/ipa/ HTTP/1.1" 200 14
ERROR django.request Internal Server Error: /kegs/7/
Traceback (most recent call last):
  File "django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 199, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "urls.py", line 23, in keg
    raise ValueError(f"keg {keg_id} is empty")
ValueError: keg 7 is empty
[21/Nov/2026 00:41:20] "GET /kegs/7/ HTTP/1.1" 500 145
WARNING django.request Not Found: /missing/
[21/Nov/2026 00:41:20] "GET /missing/ HTTP/1.1" 404 179
ERROR taproom payment failed
Traceback (most recent call last):
  File "urls.py", line 32, in pay
    raise CardDeclined("card declined")
urls.CardDeclined: card declined
WARNING django.request Payment Required: /pay/
[21/Nov/2026 00:41:20] "GET /pay/ HTTP/1.1" 402 26
```

### Read the level from the environment

The `LOGGING` dict above reads `LOG_LEVEL`. Start the server with `LOG_LEVEL=DEBUG`, and the `debug` line appears with no code change.

```bash
LOG_LEVEL=DEBUG python manage.py runserver
```

Output

```text
DEBUG taproom keg pressure read
INFO taproom tap ipa opened
WARNING taproom keg below 10%
ERROR taproom keg empty
CRITICAL taproom cooler offline
[21/Nov/2026 00:41:21] "GET /taps/ipa/ HTTP/1.1" 200 14
```

### Log a caught exception with logger.exception()

Inside `except`, `logger.exception()` logs at `ERROR` and adds the traceback. Our `pay` view also returned a 402 response, so `django.request` logged `Payment Required` at `WARNING`.

```bash
def pay(request):
    try:
        raise CardDeclined("card declined")
    except CardDeclined:
        logger.exception("payment failed")
        return JsonResponse({"error": "card declined"}, status=402)
```

Output

```text
ERROR taproom payment failed
Traceback (most recent call last):
  File "urls.py", line 32, in pay
    raise CardDeclined("card declined")
urls.CardDeclined: card declined
WARNING django.request Payment Required: /pay/
```

## Send Django logs and errors to LogBrew

### Install the packages

`logbrew-django` adds a span for each request and records each unhandled view error as an issue. `logbrew-sdk` holds the client and the logging handler. Use a server key of your LogBrew project.

```bash
python3 -m pip install logbrew-sdk logbrew-django
```

### Add the middleware and the handler to settings.py

Put this code after `MIDDLEWARE` and `LOGGING`. `LogBrewDjangoMiddleware` must come first in `MIDDLEWARE`. `LogBrewLoggingHandler` sends each record of the `taproom` logger. We sent to a local LogBrew server, so our copy passed `endpoint=` to `HttpTransport()`.

```bash
import logging
import os

from logbrew_django import configure_logbrew
from logbrew_sdk import HttpTransport, LogBrewClient, LogBrewLoggingHandler

MIDDLEWARE = ["logbrew_django.LogBrewDjangoMiddleware", *MIDDLEWARE]

client = LogBrewClient.create(api_key=os.environ["LOGBREW_SERVER_API_KEY"])
logging.getLogger("taproom").addHandler(LogBrewLoggingHandler(client))
configure_logbrew(
    client=client, transport=HttpTransport(), service_name="taproom"
)
```

### Read the issue and the logs back

We called the 4 views again and read the project with a read key. The 500 error became 1 issue named after the route. The `taproom` logs kept their levels, and `debug` stayed out because the root level was `INFO`. The 404 made no issue.

```bash
logbrew issues --since 1h
logbrew read logs --since 1h
```

Output

```text
Issues (1)
- 4ca6e2fb-76d2-57d9-879a-5a4410756489 unresolved error priority=medium GET /kegs/<int:keg_id>/ failed occurrences=1 users=unknown last_seen=2026-11-21T06:44:49.579Z service=taproom trace=980168dd9976432da150838cb57f0f04 assignee=unassigned [unversioned / production]
Logs (5)
- error payment failed service=taproom trace=430c4481db414e84bec813f60aa9aa93 [unversioned / production]
- critical cooler offline service=taproom trace=a407e883564e4ab486dd9a4921971ad4 [unversioned / production]
- info tap ipa opened service=taproom trace=a407e883564e4ab486dd9a4921971ad4 [unversioned / production]
- warning keg below 10% service=taproom trace=a407e883564e4ab486dd9a4921971ad4 [unversioned / production]
- error keg empty service=taproom trace=a407e883564e4ab486dd9a4921971ad4 [unversioned / production]
```

### Check what the issue and the log keep

The issue keeps the exception type and the route, but not the message. LogBrew writes `Unhandled exception` in its place. The log from `logger.exception()` keeps the exception name and message, the file, the function, and the line.

```bash
logbrew issues --since 1h --json | jq '.[0].attributes | {
  message, exception,
  route: .metadata.routeTemplate,
  frames: (.stackFrames | length)
}'
logbrew read logs --since 1h --severity error --search payment --json |
  jq '.[0].attributes.metadata | {
    exceptionName, exceptionMessage, fileName, functionName, lineNumber
  }'
```

Output

```text
{
  "message": "Unhandled exception",
  "exception": {
    "mechanism": {
      "handled": false,
      "type": "django.middleware"
    },
    "type": "ValueError"
  },
  "route": "/kegs/<int:keg_id>/",
  "frames": 2
}
{
  "exceptionName": "CardDeclined",
  "exceptionMessage": "card declined",
  "fileName": "urls.py",
  "functionName": "pay",
  "lineNumber": 34
}
```

## What we saw when we tested it

We ran 1 Django 6.1.3 app on Python 3.13.5 with `runserver` and `DEBUG = False`, called 4 views with curl, and read the server output. Then we added logbrew-django 0.1.12 and read what a local LogBrew server stored.

With `DEBUG = True` and no `LOGGING`, Django printed the traceback of the 500 error too. So an app that prints tracebacks in development can print none in production.

|  | No `LOGGING` | With `LOGGING` |
| --- | --- | --- |
| `logger.debug()` | No | With `LOG_LEVEL=DEBUG` |
| `logger.info()` | No | Yes |
| `logger.warning()` | Yes | Yes |
| Traceback of the 500 error | No | Yes |
| Line for the 404 | No | Yes |

## Django log levels and the django.request logger

Django uses the 5 levels of Python, `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `CRITICAL`. The root level in `LOGGING` drops each record below it.

`django.request` logs a 5xx response at `ERROR` and a 4xx response at `WARNING`. Only the 500 from an exception came with a traceback.

LogBrew keeps `warning`, `error`, and `critical` as they are, and stores `DEBUG` and `INFO` as `info`.

| Response | `django.request` | Traceback |
| --- | --- | --- |
| `500` | `ERROR` | Yes |
| `404` | `WARNING` | No |
| `402` | `WARNING` | No |

## What LogBrew records

The middleware records 1 span per request, named after the route template, such as `GET /kegs/<int:keg_id>/`. An exception in a view adds an issue with the exception type, the mechanism `django.middleware`, and `handled: false`.

The issue does not keep the exception message. To keep it, log the error with `logger.exception()`, as the `pay` view does.

A log written during a request carries the trace ID of that request. `Http404` and the other 4xx exceptions make a span with their status and no issue.

- `LogBrewDjangoMiddleware`
  - Issue: `GET /kegs/<int:keg_id>/ failed`
  - `exception.type`: `ValueError`
  - `mechanism`: `django.middleware`
  - `handled`: `false`
  - Stack frames: 2
- `LogBrewLoggingHandler`
  - Message: `payment failed`
  - `exceptionName`: `CardDeclined`
  - `exceptionMessage`: `card declined`
  - `lineNumber`: `34`

## Questions people ask

### Why does Django not log 500 errors?

With `DEBUG = False`, the default setup sends `django.request` errors only to `mail_admins`, which emails the `ADMINS`. Add a `LOGGING` dict with a console handler on the root logger to print them.

### How do I set the log level in Django?

Set `level` on the root logger in `LOGGING`. Read it from an environment variable such as `LOG_LEVEL` to change it with no code change.

### How do I log an exception with its traceback in Django?

Call `logger.exception()` inside `except`. It logs at `ERROR` and adds the traceback.

### What does disable_existing_loggers do?

With `True`, Django's own loggers stop when your `LOGGING` is applied, so `django.request` prints nothing. Keep it at `False`.

## See every Django error with its request

logbrew-django records each unhandled view error as an issue named after its route, and sends your logs with the trace of their request. Start on the generous free tier, no card needed.

[Start Free](https://logbrew.co/en)

## Sources

- [Django docs, Configuring logging](https://docs.djangoproject.com/en/6.0/topics/logging/#configuring-logging)
- [Django docs, Default logging configuration](https://docs.djangoproject.com/en/6.0/ref/logging/#django-s-default-logging-configuration)
- [Django docs, django.request](https://docs.djangoproject.com/en/6.0/ref/logging/#django-request)
- [django/django, django/utils/log.py](https://github.com/django/django/blob/main/django/utils/log.py)

## More guides for agents, Python, Node.js, and React

- [Claude Code MCP and Codex MCP server setup](https://logbrew.co/en/guides/mcp-server-claude-code-codex)
- [Use AGENTS.md in Claude Code and Codex](https://logbrew.co/en/guides/agents-md)
- [Fix the Claude overloaded error 529 and rate limit error 429](https://logbrew.co/en/guides/claude-overloaded-rate-limit-error)
- [Set up Python logging with the right log levels and exception capture](https://logbrew.co/en/guides/python-logging)
- [Structured logging with a log format and log levels you can search by field](https://logbrew.co/en/guides/structured-logging)
- [Set up the Pino logger or Winston in Node.js and keep every error](https://logbrew.co/en/guides/node-logging)
- [Set up FastAPI logging and handle errors without losing the traceback](https://logbrew.co/en/guides/fastapi-logging)
- [Add a React error boundary and log the errors it misses](https://logbrew.co/en/guides/react-error-boundary)
- [Trace ID vs span ID, decoded from a real traceparent header](https://logbrew.co/en/guides/trace-id)
- [How to fix errors and set up logs, traces, metrics & releases](https://logbrew.co/en/guides)
