A module to enrich logs with context, featuring async log contexts and scope management.
Go to file
2020-07-20 12:32:13 +00:00
.vscode fix(core): update 2020-07-20 11:57:20 +00:00
dist dependencies, first working version 2018-03-03 14:11:27 +01:00
test fix(core): update 2020-07-20 11:57:20 +00:00
ts fix(core): update 2020-07-20 11:57:20 +00:00
.gitignore fix(core): update 2020-07-20 11:57:20 +00:00
.gitlab-ci.yml fix(core): update 2020-07-20 11:57:20 +00:00
npmextra.json fix(core): update 2020-07-20 11:57:20 +00:00
package-lock.json 1.0.23 2020-07-20 11:57:20 +00:00
package.json 1.0.23 2020-07-20 11:57:20 +00:00
readme.md fix(core): update 2020-07-20 12:32:13 +00:00
tslint.json fix(core): update 2020-07-20 11:57:20 +00:00

@pushrocks/logcontext

enrich logs with context

Status for master

Status Category Status Badge
GitLab Pipelines pipeline status
GitLab Pipline Test Coverage coverage report
npm npm downloads per month
Snyk Known Vulnerabilities
TypeScript Support TypeScript
node Support node
Code Style Code Style
PackagePhobia (total standalone install weight) PackagePhobia
PackagePhobia (package size on registry) PackagePhobia
BundlePhobia (total size when bundled) BundlePhobia
Platform support Supports Windows 10 Supports Mac OS X

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');
});

Contribution

We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can contribute one time or contribute monthly. :)

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