Skip to content
Warlock.js v4

LogChannel

LogChannel<Options> is the abstract base class every built-in channel extends. Subclass it to build a custom channel — you only need to implement log(); the base handles configuration merging, level + filter checks, and date formatting. It already satisfies LogContract.

See Custom Channel for the usage guide.

abstract class LogChannel<Options extends BasicLogConfigurations = BasicLogConfigurations>
implements LogContract
MemberTypeDescription
namestringUnique identifier for the channel. Set it on your subclass.
descriptionstring?Optional human-readable description.
terminalbooleantrue preserves ANSI codes in the message; false (default) means the logger strips them via clearMessage() before the entry arrives.
constructor(configurations?: Options)Accepts the channel’s options. Schedules init() on the next tick.
logabstract (data: LoggingData): void | Promise<void>Implement this. Your write/send logic.
flushSync(): void (optional)Implement when the channel buffers in memory and needs a synchronous drain on shutdown.
getRedactConfig(): RedactConfig | undefinedReturns the channel’s redact config (additive on top of the logger-wide floor). Subclasses normally don’t override — set redact in the channel options instead.
MemberTypeDescription
init(): void | Promise<void> (optional hook)One-time async setup, called once after construction. The channel is marked ready once it resolves.
defaultConfigurationsOptionsOverride to provide option defaults (merged under user-supplied config).
channelConfigurationsOptionsThe user-supplied config (merged over defaults).
isInitializedbooleantrue once init() has resolved.
config<K extends keyof Options>(key: K): Options[K]Type-safe accessor — returns the channel config value, falling back to the default.
setConfigurations(configurations: Options): thisMerge more options into the channel config.
shouldBeLogged(data: LoggingData): booleanfalse if data.type isn’t in levels, or if the filter predicate returns false. Call it at the top of your log().
getDateAndTimeFormat(): { date: string; time: string }The resolved Day.js date/time format strings (config or defaults "DD-MM-YYYY" / "HH:mm:ss").
withBasicConfigurations(configurations: Partial<Options>): OptionsFactory helper merging a partial config with a pass-through filter baseline.

The constructor schedules init() via setTimeout(0) and flips isInitialized to true once it resolves. Entries logged in the first tick — before init() completes — can reach log() before async setup finishes. Guard against half-initialized resources in your log(), or buffer until ready. See Custom Channel.