Skip to main content

Django Log Monitoring with LogMonitor

>_ why django apps need log monitoring

Django applications handle complex request lifecycles, background tasks, management commands, and database operations. The built-in logging writes to files or the console, which is not practical when running multiple Gunicorn workers across several servers. LogMonitor centralizes all your Django logs into a single Live Console with real-time streaming and structured search.

>_ how logmonitor works with django

Create a custom Python logging handler that sends log records to the LogMonitor HTTP API. Add it to your Django LOGGING configuration in settings.py. The API returns 202 Accepted on success. All logger.info(), logger.error(), and unhandled exception logs are automatically forwarded to your LogMonitor dashboard.

>_ quick start

myapp/logmonitor_handler.py · python
import logging
import time
import requests
from django.conf import settings
class LogMonitorHandler(logging.Handler):
    def emit(self, record):
        try:
            requests.post(
                "https://api.logmonitor.io/v1/logs",
                headers={
                    "X-Logmonitor-Api-Key": settings.LOGMONITOR_API_KEY,
                    "Content-Type": "application/json",
                },
                json=[{
                    "level": record.levelname.lower(),
                    "message": self.format(record),
                    "clientTimestamp": int(time.time()),
                }],
                timeout=5,
            )
            # Returns 202 Accepted on success
        except Exception:
            self.handleError(record)
# In settings.py LOGGING config:
# 'handlers': {'logmonitor': {'class': 'myapp.logmonitor_handler.LogMonitorHandler', 'level': 'INFO'}}
# Usage: logger.error('Payment failed', extra={'order_id': 456})

>_ what you can monitor

  • $HTTP 500 errors and unhandled exceptions
  • $ORM query errors and database connection issues
  • $Celery task failures and retry events
  • $Authentication and permission denied errors
  • $Management command execution logs
  • $Middleware and signal handler errors

>_ frequently asked questions

$ Can I use LogMonitor with Django REST Framework?

Yes. Django REST Framework uses Django's standard logging. Configure the LogMonitor handler in your LOGGING settings and all DRF exception responses and log calls are forwarded automatically.

$ Does LogMonitor capture Django unhandled exceptions?

Yes. Django's built-in exception handling logs to the django.request logger. Add the LogMonitor handler to that logger in your LOGGING config and all 500 errors are sent to your Live Console.

$ Can I monitor Celery tasks running with Django?

Yes. Configure the Celery logger to use the LogMonitor handler. Task failures, retries, and any log calls inside tasks will be forwarded to LogMonitor.

$ Does the HTTP call block my Django views?

The timeout is set to 5 seconds to prevent hanging. For zero overhead, send logs asynchronously using a background thread, Django channels, or a Celery task dedicated to log forwarding.

$ Does LogMonitor work with Django on Gunicorn and uWSGI?

Yes. The custom logging handler works identically whether you run Django with Gunicorn, uWSGI, Daphne, or the development server. Each worker process sends logs independently to the LogMonitor API.

>_ related pages

>_ about logmonitor

LogMonitor.io is a log observability platform built for developers who want simple, fast, affordable log monitoring without enterprise complexity. Stream production logs from your users' devices in real-time with native Flutter and React SDKs. Set up in under 5 minutes, with plans starting at $9/month. No dashboards to configure, no query languages to learn — just your logs, live.

logmonitor --start
Ready to see your production logs in real-time?
Start Monitoring →

Plans from $9/mo · Set up in under 5 minutes