Logs Terminal Emulator Streams API
Server-side Event (SSE) Streams API for the Terminal Emulator React App.
Mostly GitHub Copilot vibecoded SSE log streaming views for dashboard clients.
This module provides a login-protected Django view,
stream_user_logs(), that streams server log output to the browser using
Server-Sent Events (SSE).
The view subscribes to a Redis Pub/Sub channel derived from the authenticated user context and forwards log records to connected clients in SSE format.
Behavior
Uses the
defaultRedis connection configured throughdjango-redis.- Verifies
smarter_settings.enable_dashboard_server_logsbefore opening a stream.
- Verifies
- Emits a retry hint and keepalive comments to keep long-lived connections
healthy through intermediate proxies.
Closes the Redis Pub/Sub connection when the stream terminates.
SSE payload format
retry: 3000is sent once when a client first connects.Each log line is sent as
data: <line>followed by a blank line.: keepalivecomments are sent during idle periods.
See also
-mod:smarter.lib.logging.redis_log_handler
- smarter.apps.dashboard.views.terminal_emulator.api.streams.stream_user_logs(request)[source]
Stream per-user server logs over Server-Sent Events (SSE).
This endpoint opens a Redis Pub/Sub subscription for the current user context and forwards incoming messages as SSE frames. When no message is available, keepalive comments are emitted so that long-lived connections remain active through reverse proxies.
- Parameters:
request (
HttpRequest) – Incoming HTTP request. The view requires authentication viadjango.contrib.auth.decorators.login_required().- Returns:
A streaming SSE response when log streaming is available; otherwise a plain-text non-streaming response describing why streaming is disabled or unavailable.
- Return type:
Union[StreamingHttpResponse,HttpResponse]- Status 200:
Streaming response created successfully.
- Status 503:
Redis is unavailable and a stream cannot be created.
- Responseheader Content-Type:
text/event-streamfor streaming responses.- Responseheader Cache-Control:
no-cachefor streaming responses.- Responseheader X-Accel-Buffering:
nofor streaming responses.- Note:
If
smarter_settings.enable_dashboard_server_logsis false, the function returns a plain-text response and does not connect to Redis.