Skip to content

Linked Context Manager

NPM VersionNPM DownloadsTypeScript

Context Manager Source

A context manager that keeps context linked between parent and child loggers.

This means that changes to the context in the parent / child / child of child loggers will affect all loggers.

Installation

bash
npm install @loglayer/context-manager-linked
bash
yarn add @loglayer/context-manager-linked
bash
pnpm add @loglayer/context-manager-linked

Usage

typescript
import { LogLayer, ConsoleTransport } from "loglayer";
import { LinkedContextManager } from '@loglayer/context-manager-linked';

const parentLog = new LogLayer({
  transport: new ConsoleTransport({
    logger: console
  }),
}).withContextManager(new LinkedContextManager());

const childLog = parentLog.child();

childLog.withContext({
  module: 'users'
});

parentLog.withContext({
  app: 'myapp'
});

parentLog.info('Parent log');
childLog.info('Child log');

// Output includes: { module: 'users', app: 'myapp' }
// for both parentLog and childLog

Changelog

View the changelog here.