Skip to content
Warlock.js v4

Logger

Logger is the central orchestrator. It holds a list of channels and forwards every log call to all of them. log is the pre-instantiated singleton exported from the package.

I want to…Use
Log at info levellog.info("module", "action", "message")
Register a channellog.addChannel(myChannel)
Retrieve a channel by namelog.channel("console")
Drop everything below a severitylog.setMinLevel("info")
Strip secrets from every entrylog.setRedact({ paths: ["context.password"] })
Time how long an operation tookconst end = log.timer("db", "query"); end()
Log an error if a condition failslog.assert(condition, "module", "action", "message")
MethodSignatureDescription
addChannel(channel: LogChannel): thisRegister a new channel. Chainable.
setChannels(channels: LogChannel[]): thisReplace the full channel list.
configure(config: { channels?: LogChannel[]; autoFlushOn?: AutoFlushEvent[]; minLevel?: LogLevel; redact?: RedactConfig }): thisOne-shot setup: channel list, auto-flush handlers, severity floor, redaction floor. Every field optional.
log(data: LoggingData): Promise<this>Pass a fully formed LoggingData object through all channels.
debug(dataOrModule: OmittedLoggingData | string, action?: string, message?: any, context?: Record<string, any>): Promise<this>Log at debug.
info(dataOrModule, action?, message?, context?): Promise<this>Log at info.
warn(dataOrModule, action?, message?, context?): Promise<this>Log at warn.
error(dataOrModule, action?, message?, context?): Promise<this>Log at error.
success(dataOrModule, action?, message?, context?): Promise<this>Log at success.
assert(condition: unknown, module: string, action: string, message: any, context?: Record<string, any>): Promise<this> | thisLog an error entry when condition is falsy; genuinely free no-op when truthy.
timer(module: string, action: string): (extra?: Record<string, any>) => Promise<this>Start a duration timer. The returned function emits an info entry with completed in <ms>ms and a durationMs field in context.
channel(name: string): LogChannel | undefinedFind a registered channel by its name property.
flushSync(): voidSynchronously invoke flushSync() on every channel that implements it.
enableAutoFlush(events: AutoFlushEvent[]): thisRegister one process handler per event that flushes before exit. Signals are flushed + re-raised; beforeExit is flushed in place. Idempotent — replaces previous handlers.
disableAutoFlush(): thisRemove every handler installed by enableAutoFlush. Safe with none registered.
setMinLevel(level: LogLevel | undefined): thisDrop entries below level before fan-out. undefined clears.
getMinLevel(): LogLevel | undefinedRead the active minimum severity.
setRedact(config: RedactConfig | undefined): thisSet the logger-wide redaction floor (applied once before fan-out). See Redaction.
getRedact(): RedactConfig | undefinedRead the active redaction floor.
FieldTypeDescription
channelsLogChannel[]The currently registered channel list.
idstringUnique identifier for this logger instance.
import { log, ConsoleLog, FileLog } from "@warlock.js/logger";
// Register channels via the fluent API
log
.addChannel(new ConsoleLog())
.addChannel(new FileLog({ storagePath: "./logs", name: "app" }));
// Positional shorthand — (module, action, message, context?)
await log.info("UserService", "login", "User authenticated");
// Full data object — level implied by log.log
await log.log({
type: "info",
module: "UserService",
action: "login",
message: "User authenticated",
});
// Retrieve a registered channel by name
const file = log.channel("file");
// Drop debug noise globally — fast-path filter
log.setMinLevel("info");
// Strip secrets before any channel sees them
log.setRedact({ paths: ["context.password", "context.*.token"] });
// Time an operation
const end = log.timer("db", "query");
const rows = await db.query(sql);
await end({ rowCount: rows.length });
// Assertion — logs at error when condition is falsy, no-op otherwise
log.assert(user !== null, "auth", "session", "user vanished mid-flight", { sessionId });
  • TypesLoggingData, OmittedLoggingData, LogLevel, AutoFlushEvent, RedactConfig
  • LogChannel — the base class for custom channels