utils/logger.ts

OGAM · src/utils/logger.ts · typescript · MIT
infra, tag:knn-classified

Simple logger that outputs to console and optionally to stderr during tests.

// Source: https://github.com/off-grid-ai/OGAM | License: MIT | Copyright 2026 Mohammed Ali Chherawalla
// Provided via justclaw.it.com; keep this notice with the code.
// Under jest, console.* is mocked to jest.fn() (see jest.setup.ts), so logger output is invisible in tests.
// When DEBUG_LOGS is set (e.g. `DEBUG_LOGS=1 npx jest <file>`), ALSO mirror every log to process.stderr —
// which jest does NOT mock — so the source's [X-SM] state-machine traces become visible while debugging a
// test, without patching the logger per-test or sprinkling process.stderr.write through the source. Opt-in
// so normal test runs stay quiet.
const stderrDebug =
  typeof process !== 'undefined' &&
  !!process.env?.JEST_WORKER_ID &&
  !!process.env?.DEBUG_LOGS;

const toStderr = (level: string, args: unkno

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key