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.logfile 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_logstoINSTALLED_APPSIn 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3662758d3d99a94746005f04e6c7579560e083045f207b2610ccc9897b5e36d0
|
|
| MD5 |
2081a6116706993cb4ba42c25b78d989
|
|
| BLAKE2b-256 |
9ee65ca36513007d48685dfaa4cbe4983f9970013f69f9c75d873eb9baac1ad1
|
File details
Details for the file django_realtime_logs-0.1.2-py3-none-any.whl.
File metadata
- Download URL: django_realtime_logs-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ca6b6fce76ebd0e3e437c070a3327dbd14b16da370457849d0b3a7bb228996b
|
|
| MD5 |
81656d7cf5350f4f3ecec16ceba8bea3
|
|
| BLAKE2b-256 |
24cf6add50536e3fe667df236cb37bf12b7056d50a1036c2847c039492f93c70
|