LogContext
constLogContext:object
Defined in: src/LogContext.ts:59
The LogContext namespace exposes the MDC operations. The class-
style LogContext.run(...) shape mirrors how Akka’s MDC is used and
keeps the public API tight without exporting the underlying
AsyncLocalStorage instance.
Type Declaration
Section titled “Type Declaration”get():
LogContextData
Read the current context. Returns the frozen empty object when
called outside any run — never undefined, never null, so
callers can .entries() over it without guarding.
Returns
Section titled “Returns”run<
T>(ctx,fn):T
Run fn with ctx as the current context. The previous context
(if any) is shadowed for the duration of the call and restored
automatically. Sync and async fn both work — AsyncLocalStorage
preserves the binding across awaits.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”() => T
Returns
Section titled “Returns”T
snapshot()
Section titled “snapshot()”snapshot():
Record<string,string|number|boolean>
Capture the current context as a plain (mutable-by-the-caller)
object — useful when you need to pass the context through a
boundary that strips Readonly (e.g. a JSON serialiser).
Returns a fresh copy every call.
Returns
Section titled “Returns”Record<string, string | number | boolean>
with()
Section titled “with()”with<
T>(extra,fn):T
Run fn with extra fields merged into the current context.
Equivalent to run({ ...get(), ...extra }, fn) but a touch
shorter at call sites that just want to add a field.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”() => T
Returns
Section titled “Returns”T