Skip to content

src/log

Tagged, leveled logging for every runtime - the one logger the whole monorepo shares.

Import this module instead of constructing package-local console wrappers so log levels, tags, formatting, and browser behavior remain consistent.

logger resolves a tagged Logger through a synchronous console sink, then upgrades its server-side formatter when node:util resolves. Keeping the sink dependency-free prevents browser bundlers from retaining an optional bare import that downstream apps would still have to install. LogLevel filtering runs through shouldEmit in per-level wrappers around the platform console or stderr sink.

The console fallback writes debug/info to process.stdout and warn/error to process.stderr when available (Bun inspect per argument when LOG_BUN_CONSOLE_DISABLED is unset, otherwise node:util inspection), or delegates to global console.* when process streams are unavailable. Browser hosts omit the LEVEL text prefix (devtools show severity) and keep only the [name] tag.

Env toggles: LOG_LEVEL (read per call) and LOG_BUN_CONSOLE_DISABLED (read once during factory init).

Browser-safe: process / Bun / window / document are all reached through globalThis and guarded, and node:util is imported ONLY on a host that has process.stderr - never in a browser, where the specifier is unresolvable - so the module works in any runtime.