logform

A composable, mutable object-based log format library for chaining and objectMode streams, used by the winston logger.

Library
npm
v2.7.0
267stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
61/100Good
Development Activity52
Maintenance36
Community76
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture75
Code Quality78
Innovation68
Learning Curve65

logform provides the format-composition system used by winston: each format is a small prototype object exposing a synchronous transform(info, opts) method that mutates a log-message info object and returns it (or a falsey value to filter the message out). Built-in formats cover common needs — json, colorize, timestamp, printf, simple, label, splat, errors, logstash, metadata, padLevels, prettyPrint, align, cli, and uncolorize — and any number of them can be chained together with format.combine.

Because info objects carry shared Symbol properties (LEVEL, MESSAGE, SPLAT) from the companion triple-beam package, formats produced by different libraries can interoperate safely without colliding on plain string keys. logform is a foundational dependency of the broader winston logging ecosystem, but is independently useful and independently published, seeing tens of millions of weekly downloads.

What You Get

  • A format(transformFn) factory for defining new custom formats
  • format.combine to chain multiple formats into a single pipeline
  • Built-in formats: json, colorize, timestamp, printf, simple, label, splat, errors, logstash, metadata, padLevels, prettyPrint, align, cli, uncolorize
  • Shared Symbol properties (via triple-beam) for level, message, and splat so formats interoperate without key collisions
  • Support for filtering out log messages entirely by returning a falsey value from a format’s transform

Common Use Cases

  • Composing a custom winston logger format pipeline (e.g. timestamp + colorize + printf)
  • Building application-specific log formats that add fields like request IDs or environment tags
  • Filtering sensitive or private log entries before they reach a transport
  • Formatting logs for downstream systems like Logstash or structured JSON log aggregators

Under The Hood

Architecture - format.js is the core factory: it validates that a given transform(info, opts) function takes at most two arguments, wraps it in a Format prototype (Format.prototype.transform = formatFn), and returns a createFormatWrap function whose .Format property exposes the class for testability — this is the pattern every built-in format (json.js, colorize.js, timestamp.js, printf.js, etc.) is built on. combine.js chains formats by iterating an array of format instances and calling each transform in sequence, stopping early if any returns a falsey info. index.js re-exports format plus every built-in format as named properties (format.json, format.combine, …), and browser.js provides a browser-safe subset. Tech Stack - Plain CommonJS JavaScript with a small, deliberate dependency set: triple-beam for shared Symbols, safe-stable-stringify for the json format, fecha for timestamp formatting, ms for the ms format, and @colors/colors for the colorize/cli formats; Babel compiles the browser build (npm run build). Code Quality - test/ contains a .test.js file per format (colorize, json, printf, combine, errors, etc.) run via Mocha with nyc coverage, and npm run pretest enforces ESLint (@dabh/eslint-config-populist) before tests run, giving each format focused, isolated test coverage. API Design - The transform(info, opts) contract is uniform across every format, so learning one format (e.g. timestamp()) transfers directly to writing a custom one via format(fn), and format.combine composes them with simple array-like chaining — the main friction for newcomers is understanding the shared-Symbol (LEVEL/MESSAGE/SPLAT) convention that lets formats interoperate.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search