HTTP Log Server — Developer Docs

Overview

This server receives logs (POST), stores them in logs.json, pushes realtime updates over WebSocket, and can archive logs into timestamped files in archives/. When a log containing "shutdown" is received, the server auto-archives the current logs and clears them.

Important files & folders

  • logs.json — current in-memory/persisted logs (JSON array)
  • archives/ — archived snapshots named logs-YYYY-MM-DDTHH-MM-SS-msZ.json
  • logs.html, logs_list.html, docs.html — UI pages

Endpoints

  • POST /log — body: { "log": "your log text" }. Adds a log, persists to disk, broadcasts via WebSocket. If the log text contains shutdown (case-insensitive) the server automatically archives current logs and clears them.
  • GET /logs — serve live logs page (logs.html)
  • GET /logs/data — returns current logs as JSON
  • GET /logs/list — UI page that lists archived snapshots with download links
  • GET /logs/archives — returns JSON array of archive filenames
  • GET /logs/download/:name — download a specific archive
  • POST /logs/clear — archive current logs and clear them
  • POST /logs/archives/clear — delete all archives
  • DELETE /logs/archives/:name — delete a single archive file
  • GET /docs — this documentation page

WebSocket

Connect to the same host (ws:// or wss://) to receive an initial dump of logs.json and live pushes of new log entries. The server emits small JSON messages: either an array of new logs or control objects like { cleared: true, archived: 'filename' }.

Examples

Send a log via curl:

curl -X POST -H "Content-Type: application/json" -d '{"log":"Player: Shutdown"}' http://localhost:3000/log

Fetch archives list:

curl http://localhost:3000/logs/archives

Download an archive (browser or curl):

curl -O http://localhost:3000/logs/download/logs-2025-01-01T12-00-00-000Z.json

Behavior notes

  • Auto-archive triggers when any posted log contains the word "shutdown" (case-insensitive).
  • Archives are simple JSON arrays — they contain the exact entries from logs.json at archive time.
  • Disk operations are synchronous for simplicity; this is fine for development but consider async handling for production/high-throughput.

Developer tips

  • To add fields (timestamps, levels) consider sending structured JSON objects instead of plain strings and updating UI code accordingly.
  • Backup your archives/ if logs are important — deletion endpoints are destructive.
  • Use the /logs/data and WebSocket to drive a richer UI or post-processing pipeline.

Back to home