JL
EN
Docs Home
Menu
Guides

Stream Logs Over WebSocket

Subscribe to public or channel-scoped real-time streams over /ws.

guide jsonlog

Stream Logs Over WebSocket

Purpose: consume real-time logs through WebSocket subscriptions.

Preconditions

  • JsonLog service is reachable.
  • WebSocket client supports query parameters and auth headers.
  • For private channels, provide a valid Bearer token for the channel owner account.

API/Script Flow

  1. Open public stream:
    • GET /ws upgrade.
  2. Open channel stream:
    • GET /ws?cid=<channel_id>.
  3. Apply level filter:
    • GET /ws?level=error or GET /ws?cid=<channel_id>&level=warn.
  4. For private channels:
    • Include Authorization: Bearer <token> in upgrade request.

HTTP/curl Flow

curl cannot complete WebSocket flow. Use a WebSocket client like wscat:

JSONLOG_BASE_URL="ws://localhost:3002"
ACCESS_TOKEN="<optional_account_token>"

# Public stream
wscat -c "${JSONLOG_BASE_URL}/ws"

# Public stream with level filter
wscat -c "${JSONLOG_BASE_URL}/ws?level=error"

# Channel stream
wscat -c "${JSONLOG_BASE_URL}/ws?cid=svc-api"

# Private channel stream (authenticated)
wscat -c "${JSONLOG_BASE_URL}/ws?cid=private-api" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}"

Validation

  • Initial message contains an array of buffered logs for that stream scope.
  • Private channel upgrade without token returns 401.
  • Private channel upgrade with wrong account token returns 404.