@logger/collector
Append-only JSONL log store and an HTTP server with ingest and read-only query. No external runtime dependencies.
Install
npm install @logger/collector --registry=http://192.168.0.15:4873
JsonlLogStore
import {JsonlLogStore} from '@logger/collector';
const store = new JsonlLogStore('.logging/logs.jsonl');
await store.append(record); // one JSON object per line (creates parent dirs)
const latest = await store.tail({ // last N matching records, in file order
limit: 10,
level: 'error',
app: 'shop',
service: 'orders',
scope: 'orders.refund',
since: '2026-07-06T00:00:00.000Z',
strict: false,
});
tail behavior:
- Returns the last
limitmatching records (default10). - A missing file returns
[](handy for fresh projects). - Invalid JSONL lines are skipped by default; set
strict: trueto throw on the first bad line.
Filters: level, app, service, scope, since (ISO-8601, inclusive on timestamp), plus limit and strict.
HTTP server
import {createHttpCollectorServer, JsonlLogStore} from '@logger/collector';
const server = createHttpCollectorServer(new JsonlLogStore('.logging/logs.jsonl'));
server.listen(4319);
Endpoints:
POST /ingest— body is a singleLogRecordor an array ofLogRecordobjects. Responds204on success,400on a bad record.GET /query?level=&app=&service=&scope=&since=&limit=— read-only tail. Returns a JSON array of matching records (same semantics asstore.tail).
Standalone server (bin)
The package ships a logging-collector binary so the server can run without application code (e.g. inside a container):
logging-collector # defaults: PORT=4319 LOG_FILE=/data/logs.jsonl HOST=0.0.0.0
PORT=4319 LOG_FILE=./logs.jsonl logging-collector
Environment:
| Var | Default | Meaning |
|---|---|---|
PORT |
4319 |
TCP port to listen on. |
HOST |
0.0.0.0 |
Bind address. |
LOG_FILE |
/data/logs.jsonl |
Backing JSONL file (created on first write). |
SIGTERM / SIGINT close the server gracefully. For the Docker image, see the root README's "Docker (collector server)" section.