UNPKG

@loglayer/context-manager

Version:

Base context manager used to implement context managers for loglayer.

51 lines (47 loc) 1.79 kB
import { IContextManager, OnChildLoggerCreatedParams } from '@loglayer/shared'; export { IContextManager, ILogLayer, OnChildLoggerCreatedParams } from '@loglayer/shared'; /** * The default context manager used by LogLayer. It is a simple k/v store for context data. * * @see {@link https://loglayer.dev/context-managers/default.html | Default Context Manager Docs} */ declare class DefaultContextManager implements IContextManager { private context; private hasContext; /** * 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; /** * Copies the parent context data to the child context data. */ onChildLoggerCreated({ parentContextManager, childContextManager }: OnChildLoggerCreatedParams): void; /** * Creates a new instance of the context manager with the same context data. */ clone(): IContextManager; } /** * A mock context manager that does nothing. Useful for use with unit testing. */ declare class MockContextManager implements IContextManager { setContext(_context?: Record<string, any>): void; appendContext(_context: Record<string, any>): void; getContext(): Record<string, any>; hasContextData(): boolean; onChildLoggerCreated(_params: any): void; clone(): IContextManager; } export { DefaultContextManager, MockContextManager };