/** * @file Lazy `Console` construction + dynamic prototype mirroring for `Logger`. * Both helpers exist as free functions (rather than `Logger` static methods) * because: * * - `constructConsole` caches the resolved `node:console` module so multiple * `new Logger()` calls don't pay the require cost more than once. Caching * at the function level is simpler than a class field that has to thread * through all callers. * - `ensurePrototypeInitialized` walks `globalConsole` once at first use and * copies any console method that isn't already on `Logger.prototype`. Doing * this lazily instead of at module load is what lets the logger be imported * during early Node.js bootstrap before stdout is ready, which would * otherwise crash with `ERR_CONSOLE_WRITABLE_STREAM`. Note on the apparent * circular import with `core.ts`: `ensurePrototypeInitialized` mutates * `Logger.prototype`, so it imports `Logger` from `./core`. `core.ts` calls * `ensurePrototypeInitialized()` from inside a method body, so the import * cycle never resolves at module-load time — by the time * `ensurePrototypeInitialized` actually runs, both modules are fully * evaluated. Same pattern as `fs/path-cache` ↔ `fs/shared`. */ import type { Console } from 'node:console'; import { Logger } from './node.js'; /** * Construct a new Console instance. */ export declare function constructConsole(...args: unknown[]): Console; /** * Lazily add dynamic console methods to Logger prototype. * * This is deferred until first access to avoid calling * Object.entries(globalConsole) during early Node.js bootstrap before stdout is * ready. */ export declare function ensurePrototypeInitialized(): void; /** * Resolve (and lazily construct + cache) the per-instance `Console` for a * logger. Ensures the prototype is initialized, then returns the cached Console * from the `privateConsole` WeakMap, building one from the stored constructor * args (or the default stdout/stderr pair) on first access. This lazy path is * what lets the logger be imported during early Node.js bootstrap before stdout * is ready, avoiding `ERR_CONSOLE_WRITABLE_STREAM`. * * @param logger - The logger whose Console to resolve. */ export declare function resolveConsole(logger: Logger): typeof console & Record;