g14o
Packages@g14o/logger

Overview

Zero-dependency isomorphic structured logger for Node.js and the browser.

Isomorphic structured logger for Node.js and the browser. Prefer a message plus optional plain-object meta — no printf-style interpolation.

Zero runtime dependencies. Same API in Node and the browser.

Install

pnpm add @g14o/logger

Requires Node >=22.18 when running on the server.

Quick start

lib/logger.ts
import { createLogger } from "@g14o/logger";

export const logger = createLogger({
  name: "cache",
  level: "info",
  formatOptions: { pretty: true },
  transports: [{ type: "console" }],
});

logger.info("Cache hit", { key: "users:1" });
logger.warn("Cache read error", { key: "users:1", err: "timeout" });

createLogger() is valid. Defaults:

OptionDefault
level"info"
transports[{ type: "console" }]
formatOptions.prettyfalse (plain console)
formatOptions.timeenabled, "time" (HH:MM:SS UTC)
redact["password", "token", "authorization"]

Transports

Built-in transports are configured as a discriminated union. Pretty mode and other formatting live under formatOptions (logger-level or per-transport overrides):

TypeOptionsOutput
consoleformatOptions?Human-readable lines; colorized when pretty: true
jsonformatOptions?One JSON object per line (or pretty-printed)
// Development — pretty console
createLogger({
  formatOptions: { pretty: true },
  transports: [{ type: "console" }],
});

// Production — structured JSON
createLogger({
  transports: [{ type: "json" }],
});

// Both (pretty only on console via transport override)
createLogger({
  transports: [
    { type: "console", formatOptions: { pretty: true } },
    { type: "json" },
  ],
});

Severity levels

Order (lowest to highest): trace < debug < info / start / success < warn < error < fatal.

Use "silent" to suppress all output. The default threshold is "info", so trace and debug are hidden unless you lower the level.

Next steps

  • Formatting — pretty console, JSON, timestamps, errors, Node vs browser
  • Examples — child loggers, request IDs, timing, redaction, cache injection
  • API reference

On this page