About
May 29, 2022
What is it?
It is an extendable isomorphic log sending library written in TypeScript for JavaScript applications in Node.js and browsers.
It can be extended with custom strategy (“when to send logs”) and service (“where to send logs”).
It does not restrict you with conventions, for example, existence of logSeverity, ErrorId, or message fields in a log.
It supports any format of logs via a custom serializer.
How it works
- You call
logger.log(payload)with any object shape. - LogStore buffers logs and can apply transformations (for example rapid-fire grouping).
- A strategy listens for new logs and emits
sendwhen it is time to flush. - The configured service serializes the batch and posts it (HTTP via native
fetchfor remote services).
See Getting started for installation and Service / Strategy for built-in plugins.
Features
- Works in browsers and Node.js
- Sends single logs or bundles to external endpoints
- Log sending strategies:
- Interval — throttle flushes while logs arrive (default 15s)
- On request — flush only when you call
sendAllLogs() - On bundle size — flush when the buffer reaches N logs (default 100)
- Instant — one log in, one send out
- Groups duplicate logs in a time window (rapid-fire grouping)
- Handles circular references in log objects (
fast-safe-stringify) - Custom per-log serialization
- Built-in remote endpoints: Sumo Logic, Loggly, Elasticsearch, plus console debugging
Runnable examples: advanced-logger example/.
Runtime environment support
The package ships dual ESM (dist/index.mjs) and CommonJS (dist/index.cjs) builds, type declarations (dist/index.d.ts), and a browser IIFE global (dist/index.global.js). It has no runtime npm dependencies (lodash throttle and safe stringify are bundled in).
- Node.js — 18+ for global
fetch; developed and tested on Node.js 24+ (see library.mise.toml) - Browser — modern browsers with native
fetchand ES2015+; consumers on older targets should transpile and polyfill