abstract-logging-with-child
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

abstract-logging-with-child

abstract-logging but with a child logger. Also, it has types.

Why would I want this?

Adding a child logger to abstract-logging is pretty simple. The README of that repository gives an example.

const logger = require('abstract-logging');
logger.child = () => logger;

but this gets tedious and easy to mess up when you have a monorepo with a bunch of packages that can take loggers. You can write your own package wrapping it to accomplish this, but I'd rather just have a package for that on NPM.

Install

npm install abstract-logging-with-child

Or, with yarn:

$ yarn add abstract-logging-with-child

Or pnpm:

$ pnpm install abstract-logging-with-child

Usage

import nullLogger from 'abstract-logging-with-child';

function thatTakesALogger(logger = nullLogger) {
  logger.info(
    'This message will be logged if there is an actual logger passed, but will just be a noop otherwise.',
  );
  const child = logger.child({
    someBinding:
      'Something you want to be included in everything the child logger logs, if there is an actual logger passed.',
  });
  child.debug('Something for the child logger.');
}

License

MIT © Matthew Fernando Garcia

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.20latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i abstract-logging-with-child

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

10.4 kB

Total Files

8

Last publish

Collaborators

  • wtg