@loglayer/context-manager
Version:
Base context manager used to implement context managers for loglayer.
61 lines (59 loc) • 2.22 kB
text/typescript
import { IContextManager, IContextManager as IContextManager$1, ILogLayer, OnChildLoggerCreatedParams, OnChildLoggerCreatedParams as OnChildLoggerCreatedParams$1 } from "@loglayer/shared";
//#region src/DefaultContextManager.d.ts
/**
* 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$1 {
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;
/**
* 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;
/**
* Copies the parent context data to the child context data.
*/
onChildLoggerCreated({
parentContextManager,
childContextManager
}: OnChildLoggerCreatedParams$1): void;
/**
* Creates a new instance of the context manager with the same context data.
*/
clone(): IContextManager$1;
}
//#endregion
//#region src/MockContextManager.d.ts
/**
* A mock context manager that does nothing. Useful for use with unit testing.
*/
declare class MockContextManager implements IContextManager$1 {
setContext(_context?: Record<string, any>): void;
appendContext(_context: Record<string, any>): void;
getContext(): Record<string, any>;
hasContextData(): boolean;
clearContext(_keys?: string | string[]): void;
onChildLoggerCreated(_params: OnChildLoggerCreatedParams$1): void;
clone(): IContextManager$1;
}
//#endregion
export { DefaultContextManager, type IContextManager, type ILogLayer, MockContextManager, type OnChildLoggerCreatedParams };