import { AutoFlushEvent, BasicLogConfigurations, LogLevel, LoggingData, OmittedLoggingData, RedactConfig } from "./types.mjs"; import { LogChannel } from "./log-channel.mjs"; //#region ../@warlock.js/logger/src/logger.d.ts declare class Logger { /** * Current channel */ channels: LogChannel[]; id: string; /** * Registered auto-flush handlers, keyed by event name. Stored so repeated * calls to `enableAutoFlush` replace rather than stack, and so * `disableAutoFlush` can remove them cleanly. */ private autoFlushHandlers; /** * Logger-wide minimum severity. When set, entries below this level are * dropped before any channel is invoked — cheaper than per-channel `levels` * filters because the fan-out loop is skipped entirely. `undefined` means * no minimum (every entry reaches every channel that accepts it). */ private minLevel?; /** * Logger-wide redaction floor. Applied once before fan-out — every * channel receives an entry with these paths already censored. Channel * configs can extend the path list (additive); they cannot remove paths * set here. */ private redactConfig?; /** * Add a new channel */ addChannel(channel: LogChannel): this; /** * Set base configurations */ configure(config: { channels?: LogChannel[]; autoFlushOn?: AutoFlushEvent[]; minLevel?: LogLevel; redact?: RedactConfig; }): this; /** * Set the logger-wide redaction floor. Applied to every entry before * fan-out; channel configs add more paths on top, never fewer. Pass * `undefined` to clear. * * @example * log.setRedact({ * paths: ["context.password", "context.*.token"], * censor: "[REDACTED]", * }); */ setRedact(config: RedactConfig | undefined): this; /** * Read the active logger-wide redact config (or `undefined`). */ getRedact(): RedactConfig | undefined; /** * Drop every entry whose severity is below `level` before fan-out. Cheaper * than per-channel `levels` filters because the loop never runs and no * channel receives the entry. Pass `undefined` to clear and accept all * levels again. * * @example * // production: silence debug noise everywhere at once * logger.setMinLevel("info"); */ setMinLevel(level: LogLevel | undefined): this; /** * Read the active minimum severity (or `undefined` when none is set). */ getMinLevel(): LogLevel | undefined; /** * Set channels */ setChannels(channels: LogChannel[]): this; /** * Normalize log data to a single object */ private normalizeLogData; /** * Make log * * Fans out a single log entry to every registered channel. Non-terminal * channels receive a copy whose `message` has had ANSI color codes stripped * — each channel sees its own shallow clone so one channel cannot observe * another's mutations (e.g. a later terminal channel still sees the original * colored message). */ log(data: LoggingData): Promise; /** * Make debug log */ debug(dataOrModule: OmittedLoggingData | string, action?: string, message?: any, context?: Record): Promise; /** * Make info log */ info(dataOrModule: OmittedLoggingData | string, action?: string, message?: any, context?: Record): Promise; /** * Make warn log */ warn(dataOrModule: OmittedLoggingData | string, action?: string, message?: any, context?: Record): Promise; /** * Make error log */ error(dataOrModule: OmittedLoggingData | string, action?: string, message?: any, context?: Record): Promise; /** * Make success log */ success(dataOrModule: OmittedLoggingData | string, action?: string, message?: any, context?: Record): Promise; /** * Make fatal log — for unrecoverable failures where the application is going * down (failed bootstrap, lost connection to a required dependency that the * caller has decided not to retry, an `uncaughtException`). * * Identical shape to {@link error}; the level is purely informational — * `fatal` does NOT auto-flush or exit. The caller decides whether to call * `await log.flush()` and `process.exit(...)`. */ fatal(dataOrModule: OmittedLoggingData | string, action?: string, message?: any, context?: Record): Promise; /** * Log an `error` entry when `condition` is falsy. No-op otherwise — the * entry is never built and channels are not invoked, so this is genuinely * free in the happy path. Mirrors the spirit of `console.assert` but routes * through the logger pipeline so persistent channels capture failures. * * @example * log.assert(user !== null, "auth", "session", "user vanished mid-flight", { sessionId }); */ assert(condition: unknown, module: string, action: string, message: any, context?: Record): Promise | Logger; /** * Start a duration timer. The returned function emits an `info` entry * with `completed in ms` and a `durationMs` field in `context` when * called. Pass an object to `end()` to merge extra fields into context. * * @example * const end = log.timer("db", "users.findById"); * const user = await usersRepo.findById(id); * end({ id, found: !!user }); */ timer(module: string, action: string): (extra?: Record) => Promise; /** * Get channel by name */ channel(name: string): LogChannel | undefined; /** * Synchronously flush logs */ flushSync(): void; /** * Asynchronously drain every channel that implements `flush()`. * * Unlike {@link flushSync}, this awaits each channel's async I/O — the * correct call for a graceful shutdown that can afford to wait * (`await log.flush()` after closing the HTTP server, before * `process.exit`). A channel whose delivery is async (a network transport, * an async disk write) implements `flush()`, not `flushSync()`. * * Channels are isolated: a channel whose flush rejects can neither prevent * the others from draining nor escape as an unhandled rejection. Channels * without `flush()` are skipped. * * @example * async function shutdown() { * await httpServer.close(); * await log.flush(); * process.exit(0); * } */ flush(): Promise; /** * Register one process-level handler per event that calls `flushSync()` * before the process terminates. * * For signal events (`SIGINT`, `SIGTERM`, `SIGHUP`, `SIGBREAK`, `SIGUSR2`) * the handler flushes and then re-raises the signal so Node's default exit * behavior runs. For `beforeExit`, the handler flushes in place — Node exits * naturally afterwards. * * Idempotent: calling with the same events replaces the previous handlers. * Call `disableAutoFlush()` to unregister. * * @example * log.configure({ * channels: [new ConsoleLog(), new FileLog()], * autoFlushOn: ["SIGINT", "SIGTERM", "beforeExit"], * }); */ enableAutoFlush(events: AutoFlushEvent[]): this; /** * Remove every handler previously registered by `enableAutoFlush`. * Safe to call when no handlers are registered. */ disableAutoFlush(): this; } /** * The package singleton. Use this for everyday logging — `log.info(...)`, * `log.error(...)`, `log.configure(...)`. Custom logger instances can be * created by instantiating `Logger` directly. * * The name is intentionally short: `log` reads naturally at the call site * (`log.info("auth", "login", "ok")`) and matches the convention used in * pino, bunyan, and most JS logging tutorials. * * Note that `log` is a `Logger` instance, **not** a function — the bare * callable form was removed when the dual `log` / `logger` exports were * collapsed into a single name. Use `log.info(...)` (or any other level * shortcut) to emit entries. */ declare const log: Logger; //#endregion export { Logger, log }; //# sourceMappingURL=logger.d.mts.map