@nickroberts/hi-winston

1.1.0 • Public • Published

hi-winston

npm version Build Status Code Coverage GitHub license

Installation

npm i @nickroberts/hi-winston

Usage

HiWinston

const { HiWinston } = require('@nickroberts/hi-winston');
const hiWinston = new HiWinston();

// root logger is required
hiWinston.add('root');

const a = hiWinston.add('a');
const ab = hiWinston.add('a.b');

a.info('a');
ab.info('ab');

/* console output:
${timestamp} [a] info: a
${timestamp} [root] info: a
${timestamp} [a.b] info: ab
${timestamp} [a] info: ab
${timestamp} [root] info: ab
*/

LogManager

const { transports, format } = require('winston');
const { LogManager } = require('@nickroberts/hi-winston');

const getSimpleConsoleTransport = label =>
  new transports.Console({
    format: format.combine(
      format.label({ label }),
      format.printf(info => `[${info.label}] ${info.level}: ${info.message}`)
    )
  });

const config = {
  transports: {
    t1: getSimpleConsoleTransport('t1'),
    t2: getSimpleConsoleTransport('t2')
  },
  loggers: {
    a: {
      transportNames: ['t1']
    },
    'a.b': {
      transportNames: ['t1', 't2']
    }
  }
};

// root logger is automatically added if not in the config
const logManager = new LogManager(config);

const a = logManager.get('a');
const ab = logManager.get('a.b');
const abc = logManager.get('a.b.c');

a.info('a info');
ab.info('a.b info');
abc.info('a.b.c info');

/* console output:
[t1] info: a info
[t1] info: a.b info
[t2] info: a.b info
[t1] info: a.b info
[t1] info: a.b.c info
[t2] info: a.b.c info
[t1] info: a.b.c info
*/

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    6
    • latest

Version History

Package Sidebar

Install

npm i @nickroberts/hi-winston

Weekly Downloads

6

Version

1.1.0

License

MIT

Unpacked Size

33.5 kB

Total Files

16

Last publish

Collaborators

  • nicholasjay