Documentation / @zerotal/core / logger / LogManager
Class: LogManager
Defined in: logger/LogManager.ts:84
The engine behind Zerotal's logging: builds a LogChannel for every entry in LoggingConfigShape.channels, enriches each LogEntry (timestamp, hostname, pid, app/env, request id), filters by each channel's minimum LogLevel, and dispatches the write.
Implements BoundLogger, so the five level methods log to the default channel; use channel to target another and withContext for contextual logging. Normally resolved via the Log facade rather than constructed directly.
Channel write failures are swallowed (reported to stderr) so logging can
never throw into application code.
Example
const log = new LogManager({
default: "console",
channels: { console: { driver: "console", format: "pretty" } },
});
log.info("Server started", { port: 3000 });
log.channel("console").error("Boom", {}, new Error("kaboom"));
Implements
Constructors
Constructor
new LogManager(
config,enrich?,override?):LogManager
Defined in: logger/LogManager.ts:103
Parameters
config
Channel map and default-channel selection.
enrich?
Partial<_Enrich>
Overrides for the enrichment fields (app, env,
hostname, pid); hostname and pid default to the current host/process.
override?
When supplied, replaces the default channel's implementation with this LogChannel and skips building the rest — primarily used in tests.
Returns
LogManager
Throws
If a stack channel references an unknown channel name, or
a channel declares an unknown driver.
Channels
channel()
channel(
name):BoundLogger
Defined in: logger/LogManager.ts:248
Return a BoundLogger that writes to the named channel instead of the default. Unknown channel names are silently ignored (nothing is emitted).
Parameters
name
string
Name of a channel from the config.
Returns
Example
log.channel("daily").info("Written to today's rotating file");
Context
withContext()
withContext(
extra):BoundLogger
Defined in: logger/LogManager.ts:267
Return a BoundLogger on the default channel that merges extra into
the context of every entry it emits. Per-call context keys override the
shared ones.
Parameters
extra
Record<string, unknown>
Context fields shared across all subsequent log calls.
Returns
Example
const scoped = log.withContext({ orderId: 99 });
scoped.info("Charged"); // context: { orderId: 99 }
scoped.warn("Retry", { attempt: 2 }); // context: { orderId: 99, attempt: 2 }
scope()
scope(
name):BoundLogger
Defined in: logger/LogManager.ts:286
Return a BoundLogger that tags every entry with the subsystem it
came from. The console channel renders the tag as [FLOW]; file and JSON
channels keep it as a scope field, so a log file can be filtered by source.
Parameters
name
string
Subsystem name, e.g. "flow", "queue".
Returns
Example
const log = Log.scope("queue");
log.info("Worker started", { queues: ["default"] });
// 01:08:35.224 INFO [QUEUE] Worker started {"queues":["default"]}
Logging
debug()
debug(
msg,ctx?,err?):void
Defined in: logger/LogManager.ts:190
Log a debug-level message to the default channel.
Parameters
msg
string
ctx?
Record<string, unknown>
err?
unknown
Returns
void
Implementation of
info()
info(
msg,ctx?,err?):void
Defined in: logger/LogManager.ts:194
Log an info-level message to the default channel.
Parameters
msg
string
ctx?
Record<string, unknown>
err?
unknown
Returns
void
Implementation of
warn()
warn(
msg,ctx?,err?):void
Defined in: logger/LogManager.ts:198
Log a warn-level message to the default channel.
Parameters
msg
string
ctx?
Record<string, unknown>
err?
unknown
Returns
void
Implementation of
error()
error(
msg,ctx?,err?):void
Defined in: logger/LogManager.ts:202
Log an error-level message to the default channel.
Parameters
msg
string
ctx?
Record<string, unknown>
err?
unknown
Returns
void
Implementation of
fatal()
fatal(
msg,ctx?,err?):void
Defined in: logger/LogManager.ts:206
Log a fatal-level message to the default channel.
Parameters
msg
string
ctx?
Record<string, unknown>
err?
unknown
Returns
void
Implementation of
table()
table(
msg,rows,level?):void
Defined in: logger/LogManager.ts:232
Log msg with rows attached, rendered as a box-drawn table by the console
channel. Past three or four keys an inline JSON blob stops being readable;
the same data in columns can be scanned.
The rows are ordinary context, so file and JSON channels record what any other level method would have recorded — only the presentation differs.
Parameters
msg
string
rows
One object (rendered as key/value rows) or a list of objects (rendered as a column per key, with a header).
level?
LogLevel = "info"
Severity to emit at. Defaults to info.
Returns
void
Example
Log.table("Compile summary", { compiled: 4, cached: 2, runtime: 8 });
Log.table("Slow routes", [
{ route: "/posts", ms: 812 },
{ route: "/search", ms: 1204 },
], "warn");
Implementation of
Other
tap()
statictap(fn): () =>void
Defined in: logger/LogManager.ts:400
Register a sink invoked for every log entry, after enrichment and before the
channel write. Used by @zerotal/monitor to surface logs in the panel.
Returns an unsubscribe function.
Parameters
fn
(entry) => void
Returns
() => void