Libraries
    Preparing search index...

    Variable LogContextConst

    LogContext: {
        current(): Logger | undefined;
        enrichWith<T>(properties: Record<string, unknown>, fn: () => T): T;
        getStore(): LogContextStore | undefined;
        run<T>(logger: Logger, fn: () => T): T;
        runWithCorrelationId<T>(correlationId: string, fn: () => T): T;
    } = ...

    Ambient logger context using AsyncLocalStorage.

    Zero overhead when not used — the AsyncLocalStorage instance is only created once, and getStore() is a near-zero-cost operation.

    Type Declaration

    • current: function
    • enrichWith: function
      • Runs a callback with additional enrichment properties added to the ambient logger context.

        Type Parameters

        • T

        Parameters

        • properties: Record<string, unknown>

          additional properties to add to the context logger

        • fn: () => T

          the async function to run

        Returns T

        the result of the callback

    • getStore: function
    • run: function
      • Runs a callback with the given logger as the ambient context.

        Type Parameters

        • T

        Parameters

        • logger: Logger

          the logger to set as ambient

        • fn: () => T

          the async function to run within the context

        Returns T

        the result of the callback

    • runWithCorrelationId: function
      • Runs a callback with a correlation ID set in the ambient context.

        Type Parameters

        • T

        Parameters

        • correlationId: string

          the correlation ID to set

        • fn: () => T

          the async function to run

        Returns T

        the result of the callback

    LogContext.run(logger, async () => {
    const log = LogContext.current()!;
    log.info('Inside context');
    });