log-bundler

raw JSON →
0.5.4 verified Sat Apr 25 auth: no javascript

A JavaScript/TypeScript library that collects multiple log messages and emits them as a single JSON log line. Version 0.5.4 is the latest stable release; the project is pre-1.0.0 with documentation promised at 1.0.0. It simplifies structured logging by buffering logs and flushing them as a batch, ideal for reducing I/O in high-throughput Node.js applications. Simpler than full-featured frameworks like Winston or Pino, but limited in features and currently lacks comprehensive docs.

error TypeError: log_bundler_1.default is not a constructor
cause Using default import in ESM with older version (<0.5.0) or incorrect import style.
fix
Use named import: import { LogBundler } from 'log-bundler'
error ERR_REQUIRE_ESM
cause Using require() with an ESM-only package version.
fix
Use import syntax or convert your project to ESM. Alternatively, for CommonJS, use dynamic import: const { LogBundler } = await import('log-bundler')
error Cannot find module 'log-bundler'
cause Package not installed or incorrect import path.
fix
Run: npm install log-bundler
error Property 'log' does not exist on type 'typeof import(...)'
cause TypeScript not recognizing instance methods due to wrong import (importing the class instead of an instance).
fix
Instantiate LogBundler first: const bundler = new LogBundler(); then call bundler.log()
gotcha Pre-1.0.0 API may break in minor versions. Semantic versioning not guaranteed.
fix Pin to exact version or prepare for breaking changes.
deprecated Certain configuration options (e.g., 'outputFile') may be removed in future releases.
fix Use standard output streams instead of custom output file option.
gotcha Calling flush() synchronously may emit logs asynchronously; ensure proper await if flush returns a promise.
fix Use 'await bundler.flush()' if flush() returns a promise.
breaking Version 0.5.0 changed the export from default to named exports. 'require('log-bundler')' no longer returns a constructor.
fix Use 'import { LogBundler } from 'log-bundler'' or 'const { LogBundler } = require('log-bundler')'.
gotcha Log levels are case-sensitive and must be lowercase ('info', 'error'). Using uppercase 'INFO' will not filter correctly.
fix Always use lowercase level strings.
npm install log-bundler
yarn add log-bundler
pnpm add log-bundler

Show how to create a LogBundler, add individual logs, and flush them as a batch JSON log.

import { LogBundler } from 'log-bundler';

const bundler = new LogBundler({
  batchSize: 10,
  flushInterval: 1000,
  level: 'info'
});

bundler.log('info', 'This is a log message', { userId: 123 });
bundler.log('error', 'An error occurred', { errorCode: 500 });

// Manually flush to write bundled logs
bundler.flush();