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
import loggingimport timeimport requestsfrom django.conf import settingsclass 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
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.
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.
Yes. Configure the Celery logger to use the LogMonitor handler. Task failures, retries, and any log calls inside tasks will be forwarded to LogMonitor.
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.
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.