logstream-server
A lightweight, real-time log ingestion and streaming service built with PHP 8.3 and ReactPHP.
Overview
logstream-server receives log messages from your applications over HTTP and streams them to a browser-based UI in real-time over WebSockets. It supports two storage backends — a flat-file JSONL store for zero-dependency setups, and MariaDB for higher-volume production deployments.
[ Your apps ] ── POST /api/logs ──▶ [ HTTP :8081 ]
│
saves to storage
(MariaDB / JSONL)
│
broadcasts via
▼
[ WS :8080 ] ──▶ [ React UI ]
Live demo
A public demo runs on Render’s free plan, filled with fake traffic from ShopFast, a made-up shop of six services:
| Server | https://logstream-demo.onrender.com (API docs at the root) |
| Demo traffic | https://logstream-demo.onrender.com/demo: run scenarios (a checkout, a declined card, a gateway timeout…), backfill history or keep traffic flowing |
| UI | Open the demo, already connected |

The service sleeps after 15 minutes without traffic (the first request takes about a minute to wake it), and its logs are wiped on every spin-down, then refilled on start. The keys are public: don’t send real data. The demo page and its endpoints only exist with DEMO_MODE=true; see Render: demo data.
Features
- Real-time streaming — every ingested log is immediately broadcast to all connected UI clients via WebSocket
- Dual auth — separate write key (
API_SECRET) for your apps and read key (UI_SECRET) for the UI - Batch ingestion — send many log entries in a single HTTP request under a shared
batch_id - Trace IDs — correlate entries across services with
trace_id(UUID) andbatch_id - Rich search — filter by application, user agent, level, category, date range, trace, batch, or free-text message search
- Two storage backends — JSONL daily files (zero deps) or MariaDB (production scale)
- ULID primary keys — time-sortable IDs that double as an implicit
ORDER BY timestamp
Quick start
1. Clone and configure
git clone https://github.com/guibranco/logstream-server.git
cd logstream-server
cp .env.example .env
# Edit .env and set API_SECRET and UI_SECRET
2. Install dependencies
composer install --no-dev --optimize-autoloader
3. Start the server
php bin/server.php
The server starts two listeners:
| Port | Protocol | Purpose |
|---|---|---|
8081 | HTTP | REST API — ingest and search logs |
8080 | WebSocket | Real-time push to the UI |
4. Send your first log
curl -s -X POST http://localhost:8081/api/logs \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <API_SECRET>" \
-H "User-Agent: MyApp/1.0" \
-d '{
"app_key": "my-app",
"app_id": "production",
"level": "info",
"category": "startup",
"message": "Hello, logstream!"
}'
API reference
Authentication
| Endpoint | Key required |
|---|---|
POST /api/logs | Authorization: Bearer <API_SECRET> |
GET /api/logs | Authorization: Bearer <UI_SECRET> |
GET /api/logs/:id | Authorization: Bearer <UI_SECRET> |
GET /api/health | None — public |
Log entry fields
| Field | Type | Required | Notes |
|---|---|---|---|
app_key | string ≤ 100 | ✅ | Application slug, e.g. billing-api |
app_id | string ≤ 100 | ✅ | Instance / environment, e.g. production |
message | string | ✅ | Human-readable description |
level | enum | ❌ | debug info notice warning error critical (default: info) |
category | string ≤ 100 | ❌ | Free-form grouping tag (default: general) |
trace_id | UUID | ❌ | Client-supplied correlation ID; auto-generated if omitted |
batch_id | UUID | ❌ | Groups entries from the same request or job |
user_agent | string | ❌ | Captured from the User-Agent header automatically |
context | object | ❌ | Arbitrary JSON payload |
timestamp | ISO 8601 | ❌ | When the event occurred; defaults to server receive time |
sender_ip | string | — | Set by the server to the client’s IP address; cannot be supplied. Behind a reverse proxy, set TRUSTED_PROXIES |
transport | string | — | Set by the server: tcp (HTTP) or udp; cannot be supplied |
Batch ingestion
Send multiple entries in one request by placing them in a logs array. Fields set at the top level (app_key, app_id, batch_id) are inherited by every entry in the array:
{
"app_key": "billing-api",
"app_id": "production",
"batch_id": "550e8400-e29b-41d4-a716-446655440000",
"logs": [
{ "level": "info", "category": "payments", "message": "Charge initiated" },
{ "level": "error", "category": "payments", "message": "Charge declined", "context": { "code": "card_declined" } }
]
}
Bare arrays
Fluent Bit, Vector and similar tools send a plain JSON array. It is accepted as a batch; since there is no top level, pass app_id (and, in file mode, app_key) as the X-App-Id / X-App-Key headers:
X-App-Id: vinhedo-3
[
{ "level": "error", "category": "nginx-access", "message": "GET /api/repos 502" },
{ "level": "warning", "category": "nginx-access", "message": "GET /favicon.ico 404" }
]
Search parameters
GET /api/logs accepts the following query parameters:
| Parameter | Description |
|---|---|
app_key | Exact match |
app_id | Exact match |
level | Exact match |
category | Partial match |
user_agent | Partial match |
trace_id | Exact match |
batch_id | Exact match |
sender_ip | Exact match |
transport | tcp or udp (exact match) |
date_from | ISO 8601 — inclusive lower bound |
date_to | ISO 8601 — inclusive upper bound |
search | Substring match on message |
context[<path>] | context property equals value; dots reach nested objects (context[order.id]=42) |
context_not[<path>] | context property differs from value or is absent |
context_search | Free text across context keys and values, case-insensitive (min. 3 chars). MariaDB matches whole words via FULLTEXT (migration 006); file storage matches substrings |
limit | Max entries returned (default 100, max 1000) |
offset | Pagination offset (default 0) |
WebSocket
Connect to ws://host:8080?token=<UI_SECRET> (or wss:// when behind Nginx with TLS).
Every ingested log entry is broadcast as:
{
"type": "log",
"data": { ...LogEntry }
}
The client can also send { "type": "ping" } to receive a { "type": "pong" } keepalive response.
Deployment guides
Choose the guide that matches your environment:
- Ubuntu — PHP 8.3 + systemd + Nginx + Certbot
- Windows — PHP 8.3 + NSSM Windows Service + optional Nginx
- Docker — Docker Compose + Nginx container + Certbot container
- Render (free demo) — single-port image with Caddy, file storage, Render Blueprint