@tinylogs/client
v0.1.0
Published
Tiny fire-and-forget log client for tinylogs.
Readme
@tinylogs/client
Tiny, zero-dependency, fire-and-forget log client for a tinylogs server. Batches log records in memory and ships them over HTTP. Never throws, never blocks your app.
Install
npm install @tinylogs/clientRequires Node ≥18 (uses the global fetch), or pass your own fetchImpl.
Usage
import { TinyLogsClient } from '@tinylogs/client';
const logs = new TinyLogsClient({
url: 'http://localhost:4700', // server base URL (the client appends /ingest)
token: process.env.TINYLOGS_TOKEN!, // ingest token from `tinylogs init`
service: 'my-service', // stamped on every log
});
logs.info('reminder sent', { user: '12345' });
logs.warn('slow response', { ms: '820' });
logs.error('boom', { user: '12345' });
await logs.close(); // flush on shutdownLevels are conventional labels (level: 'info' | 'warn' | 'error'), not a first-class field.
Options
| Option | Default | Description |
| --- | --- | --- |
| url | — | Server base URL (required). |
| token | — | Bearer ingest token (required). |
| service | — | Service name on every record (required). |
| batchSize | 50 | Flush once this many records are buffered. |
| flushInterval | 1000 | Periodic auto-flush interval (ms). The timer is unref()'d. |
| onError | — | Called on a failed flush; errors never propagate to your app. |
| fetchImpl | global fetch | Inject a custom fetch (e.g. for tests). |
Because the flush timer is unref()'d, always await client.close() (or await client.flush()) before your process exits, or buffered logs may be lost.
