Skip to main content

Realtime log viewer for Django using Channels

Project description

django-realtime-logs

A real-time log viewer for Django using WebSocket and Django Channels.
It allows developers to view server logs live in the browser, making debugging easier without relying on external tools like Grafana.


Features

  • Real-time streaming of your Django runtime.log file via WebSocket.
  • Simple UI to display logs with auto-scrolling.
  • Built as a reusable Django app, easy to integrate.
  • Uses Django Channels for WebSocket support.
  • Lightweight and minimal dependencies.

Installation

pip install django-realtime-logs

Usage

  • Add django_realtime_logs to INSTALLED_APPS In your settings.py, add:
INSTALLED_APPS = [
    # existing apps...
    'django_realtime_logs',
]

ASGI_APPLICATION = 'your_project_name.asgi.application'  # Replace with your ASGI module path

# Configure your channel layers (using InMemoryChannelLayer for development)
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels.layers.InMemoryChannelLayer',
    },
}
  • Configure Logging in settings.py Make sure your logging configuration writes logs to runtime.log in your project directory:
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': BASE_DIR / 'runtime.log',
        },
    },
    'root': {
        'handlers': ['file'],
        'level': 'DEBUG',
    },
}
  • Include /logs/ and set up WebSocket with ASGI(asgi.py) Modify your asgi.py to route HTTP and WebSocket connections:
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from django_realtime_logs.routing import websocket_urlpatterns

application = ProtocolTypeRouter({
    "http": get_asgi_application(),
    "websocket": AuthMiddlewareStack(URLRouter(websocket_urlpatterns)),
})
  • Include /logs/ in urls.py Add the logs route to your main urls.py:
path("logs/", include("django_realtime_logs.urls")),

-You must use an ASGI server like daphne or uvicorn to support WebSockets. -Install daphne

pip install daphne

-Run the server

daphne -p 8001 your_project_name.asgi:application

Replace your_project_name with your Django project folder name.

  • Visit /logs/ in the browser
http://localhost:8001/logs/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_realtime_logs-0.1.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_realtime_logs-0.1.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file django_realtime_logs-0.1.2.tar.gz.

File metadata

  • Download URL: django_realtime_logs-0.1.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django_realtime_logs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3662758d3d99a94746005f04e6c7579560e083045f207b2610ccc9897b5e36d0
MD5 2081a6116706993cb4ba42c25b78d989
BLAKE2b-256 9ee65ca36513007d48685dfaa4cbe4983f9970013f69f9c75d873eb9baac1ad1

See more details on using hashes here.

File details

Details for the file django_realtime_logs-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_realtime_logs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ca6b6fce76ebd0e3e437c070a3327dbd14b16da370457849d0b3a7bb228996b
MD5 81656d7cf5350f4f3ecec16ceba8bea3
BLAKE2b-256 24cf6add50536e3fe667df236cb37bf12b7056d50a1036c2847c039492f93c70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page