This package has been deprecated

Author message:

logcontext has been deprecated in favour of @pushrocks/logcontext - please upgrade asap!!!

logcontext
TypeScript icon, indicating that this package has built-in type declarations

1.0.22 • Public • Published

logcontext

enrich logs with context

Availabililty

npm git git docs

Status for master

build status coverage report npm downloads per month Dependency Status bitHound Dependencies bitHound Code Known Vulnerabilities TypeScript node JavaScript Style Guide

Usage

Use TypeScript for best in class instellisense.

the logconext module exposes an easy to use syntax for nodejs style async logcontexts.

let testLogger = new logcontext.Logger('testNamespace');

testLogger.scope(async () => {
  testLogger.addData('id1', {
    someData: 'someValue'
  });
  testLogger.log('hi');
  testLogger.error(new Error('custom error message'));
  setTimeout(() => {
    outsideFunction(); // log scope will travel through callbacks and promises
  }, 2000);
});

let outsideFunction = () => {
  // Note:
  // the below testLogger reference will have different contexts
  // depending from which scope "outsideFunction" was called".
  testLogger.log('some message');
};

class Logger

import { Logger } from 'logcontext';

// instantiate new Logger
// argument optional, if left empty auto generated shortid will be used
let myLogger = new Logger('myNamespace');

// create a scope
myLogger.scope(async () => {
  // everything that is appended to the call stack from inside here will have all appended context data available

  // add some scoped context information
  myLogger.addData('customerId', '12345678');

  // will log something with priviously appended context of this scope in place
  myLoger.log('awesomeText');
});

For further information read the linked docs at the top of this README.

MIT licensed | © Lossless GmbH | By using this npm module you agree to our privacy policy

repo-footer

Dependencies (4)

Dev Dependencies (3)

Package Sidebar

Install

npm i logcontext

Weekly Downloads

1

Version

1.0.22

License

MIT

Unpacked Size

34.2 kB

Total Files

19

Last publish

Collaborators

  • lossless