UNPKG

@loglayer/context-manager-linked

Version:

Context manager for loglayer that keeps context between parent and all children.

45 lines (43 loc) 1.53 kB
import { IContextManager, OnChildLoggerCreatedParams } from "@loglayer/context-manager"; //#region src/LinkedContextManager.d.ts /** * A context manager that keeps context data synchronized between parent and all children (bi-directional). */ declare class LinkedContextManager implements IContextManager { private contextContainer; /** * Sets the context data to be included with every log entry. Set to `undefined` to clear the context data. */ setContext(context?: Record<string, any>): void; /** * Appends context data to the existing context data. */ appendContext(context: Record<string, any>): void; /** * Returns the context data to be included with every log entry. */ getContext(): Record<string, any>; /** * Returns true if context data is present. */ hasContextData(): boolean; /** * Clears the context data. If keys are provided, only those keys will be removed. * If no keys are provided, all context data will be cleared. */ clearContext(keys?: string | string[]): void; /** * Links the child context manager's context to be the same as the parent context manager's context. */ onChildLoggerCreated({ parentContextManager, childContextManager }: OnChildLoggerCreatedParams): void; /** * Creates a new instance of the context manager that shares the same context data. * The clone maintains a bi-directional link with the original context manager. */ clone(): IContextManager; } //#endregion export { LinkedContextManager };