dowjones / namespaced-console-logger

Minimal namespaced stdout / stderr logger with a timestamp for the browser and Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Namespaced Console Logger

Build Status NPM version

Minimal namespaced stdout / stderr logger with a timestamp for the browser and Node.js.

The logger satisfies three requirements below and attempts to do nothing else:

  1. Is small: has no dependencies & <50 loc (for the browser)
  2. Has a timestamp
  3. Has a namespace

Example output:

2015-08-10T20:09:20.526Z (namespace) INFO: Hello world!

Usage

import createLoggers from 'namespaced-console-logger';

const loggers = createLoggers();
const logger = loggers.get('namespace');

logger.info('Hello %s!', 'world');
  • createLoggers() takes a minimum logging level, which is one of: ['info', 'warn', 'error'] and defaults to info. For example if you select warn, all info logs will be ignored. warn and error logs will be displayed.

Support for formatting and arbitrary metadata

import createLoggers from 'namespaced-console-logger';

const loggers = createLoggers('info', '{{timestamp}} {{hostname}} {{calculatedValue}} ({{namespace}}) {{level}}:', { hostname: 'machinename', calculatedValue: () =>  { return 1 + 2; } });
const logger = loggers.get('namespace');

//2015-08-10T20:09:20.526Z machinename 3 (namespace) INFO: Hello world!
logger.info('Hello %s!', 'world');

License

MIT

About

Minimal namespaced stdout / stderr logger with a timestamp for the browser and Node.js.

License:MIT License


Languages

Language:JavaScript 100.0%