Const
Ambient logger context using AsyncLocalStorage.
AsyncLocalStorage
Zero overhead when not used — the AsyncLocalStorage instance is only created once, and getStore() is a near-zero-cost operation.
getStore()
Returns the ambient logger, or undefined if no context is active.
undefined
Runs a callback with additional enrichment properties added to the ambient logger context.
additional properties to add to the context logger
the async function to run
the result of the callback
Returns the raw store, useful for enrichers to read correlation IDs.
Runs a callback with the given logger as the ambient context.
the logger to set as ambient
the async function to run within the context
Runs a callback with a correlation ID set in the ambient context.
the correlation ID to set
LogContext.run(logger, async () => { const log = LogContext.current()!; log.info('Inside context');}); Copy
LogContext.run(logger, async () => { const log = LogContext.current()!; log.info('Inside context');});
Ambient logger context using
AsyncLocalStorage.Zero overhead when not used — the
AsyncLocalStorageinstance is only created once, andgetStore()is a near-zero-cost operation.